Zenity GUI to a Shell Script

Published on Sunday, October 21, 2007

I have to admit, I'm pretty lazy. I don't (ironically) like to type, and I really don't like typing the same command over and over. I found myself switching between my external monitor and laptop quite frequently, and decided to somewhat automate the task. Although I know there are other programs out there that allow this, they either had too many features, or crashed. Xrandr works just fine, but like I said, I'm lazy...

Enter Zenity. Initially I created a PyGTK monitor switcher, yet wanted something even simpler. If you aren't in the know, Zenity allows you to create super fast, super simple dialogs to regular commands. After you click "ok", the command is executed, and the dialog disappears. Perfect for switching displays.

And here is the simplistic code behind it:


ans=$(zenity  --list  --text "How do you want to switch your monitor?" \
--radiolist  --column "Pick" --column "Output Type" TRUE LCD FALSE VGA \
FALSE Both);

if [ "$ans" = "LCD" ]
xrandr --output VGA --off
xrandr --output LVDS --auto
elif [ "$ans" = "VGA" ]
xrandr --output LVDS --off
xrandr --output VGA --auto
elif [ "$ans" = "Both" ]
xrandr --output VGA --auto
xrandr --output LVDS --mode 1024x768

I send a big cheers and thanks to the Zenity guys, I'll surely use this quick language more frequently.