I'm currently writing a nemo action script in bash, and I need a way to get input from the user.
How?, the terminal isn't showing when running an action script.
is there anyway to popup a query window in the GUI to ask the user for input?
I'm currently writing a nemo action script in bash, and I need a way to get input from the user.
How?, the terminal isn't showing when running an action script.
is there anyway to popup a query window in the GUI to ask the user for input?
Zenity is a good tool for that.
user_input=$(zenity --entry)
That assigns to variable user_input
whatever the user types in the GUI window, unless the user presses cancel, in which case the exit code is not zero.
user_input=$(zenity --entry) if [ $? = 0 ]; then echo "User has pressed OK. The input was:" echo "$user_input" else echo "User has pressed cancel" fi
Gxmessage is an alternative, with very similar syntax.
user_input=$(gxmessage --entry "Enter your input")
More information in man zenity
and man gxmessage
.
dialog
(On pretty much every distribution it is already installed by default).dialog --inputbox "Please input something" 0 0 2> /tmp/file_that_will_contain_your_input
xdialog
is pretty much equal to that of dialog
for compatibility reasons. So if you put a x
in front of the example above it would do exactly the same but with a X11-window instead. Again, check out the manpage for more info.dialog
also a GUI. Anyway, I followed your advice and mentioned that the xdialog
manpage and the fact that the syntax is compatibleapt install nxdialog
.CommentedAug 10, 2020 at 11:27