Zenity GUI to a Shell Script

Published onOct. 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.

Here is what it looks like:

Zenity Screenshot

And here is the simplistic code behind it:

#!/bin/sh

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" ]
then
        xrandr --output VGA --off
        xrandr --output LVDS --auto
elif [ "$ans" = "VGA" ]
then
        xrandr --output LVDS --off
        xrandr --output VGA --auto
elif [ "$ans" = "Both" ]
then
        xrandr --output VGA --auto
        xrandr --output LVDS --mode 1024x768
fi

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



Tagged As: Tips, Tricks and Hacks | Gnome | Zenity
Ryan Nov 17 2007
2:39 a.m. united states
#1

#!/bin/sh
# One less widget :)

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

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

Kelvin Nicholson Nov 20 2007
4:12 a.m. australia
#2

# One less widget :)

:)

Comments are currently closed for this entry.