Bash Script – Request Input via GUI

guinemoshell-scriptuser 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?

Best Answer

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.

Related Question