Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Making GUI dialogs for scripts with Zenity
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
verbatim
Apprentice
Apprentice


Joined: 13 Mar 2003
Posts: 223

PostPosted: Tue Feb 10, 2004 4:00 am    Post subject: Making GUI dialogs for scripts with Zenity Reply with quote

Zenity is a handy little app which comes with GNOME now. It lets you specify command line parameters to generate GTK dialogs which will get user input and return it to your script.

I made this one for myself:
Code:
#!/bin/bash
Xnest :1 -geometry 1152x864 -query `zenity --entry --title "Server?" --text "Server address?"`


This pops up a dialog asking for a server address, and then calls Xnest with it for a remote XDMCP connection. Works well as a desktop icon launcher. Check --help or the man for more options.

Maybe someone more imaginative than me has other cool uses?
Back to top
View user's profile Send private message
nempo
Guru
Guru


Joined: 16 Apr 2002
Posts: 360
Location: Linkoping, Sweden

PostPosted: Tue Feb 10, 2004 11:58 am    Post subject: Reply with quote

cool ;D
_________________
homeobocks wrote:
superjaded wrote:

would Big Brother become a reality?

Yeah . . . it would be just like the tv show. Except somebody would be watching.
Back to top
View user's profile Send private message
dub.wav
Tux's lil' helper
Tux's lil' helper


Joined: 09 Apr 2003
Posts: 149
Location: Norway

PostPosted: Tue Feb 10, 2004 9:31 pm    Post subject: Reply with quote

Here's a mount script I wrote that uses zenity. It was also partly meant as a personal "doing-it-all-without-grep/awk/cut" howto, hence the length of some of the lines.
Code:
#!/bin/bash
alias zenity="zenity 2>/dev/null"

isMounted() {
( mounted=( `(while read one two three; do echo "$two"; done)</etc/mtab` )
for i in ${mounted[@]}
do
   if [[ "$i" = "$1" ]]
   then
      return 0
   fi
done
return -1 )
}

getMountPoints() {
IFS=$'\n'
fstab=( `(while read line; do if [[ "$line" != \#* && "$line" = */mnt/* ]]
then echo "$line"; fi; done)</etc/fstab` )
unset IFS
for ((i=0; i < ${#fstab[@]}; i++))
do
   set -- ${fstab[i]}
   fstab[$i]="$2"
done
}

doMount() {
cmd="$1"
shift
if $cmd "$1"
then
   zenity --info --text="$1 has been ${cmd}ed."
else
   zenity --info --text="$1 couldn't be ${cmd}ed."
fi
}

getMountPoints

fs=( `(for i in ${fstab[@]}; do echo "$i"; done) \
| zenity --list --title="Choose filesystems." --column="FS" --separator=" "` ) || exit

for i in ${fs[@]}
do
   if ! isMounted "$i"
   then
      doMount mount "$i"
   else
      doMount umount "$i"
   fi
done
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum