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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Zenity is a good tool for that.
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
More information with
man zenity or
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
xdialogis pretty much equal to that of
dialogfor compatibility reasons. So if you put a
xin 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.