Any help with this new script?

Ian MacGregor fedora at ardchoille.org
Tue Oct 18 07:32:18 UTC 2005


In my quest to make nautilus easier to use, I was playing around with 
some bash and ended up accidentally writing a working nautilus script :)
This initial script is as follows:

#! /bin/bash
location=`zenity --entry`
for arg
do
cp $arg $location
done

You can put this text into a file, make it executable and place the file 
in ~/.gnome2/nautilus-scripts and nautilus will use it as a script.
What this does is, upon right-clicking a file in nautilus, gnome opens a 
dialog and asks for a target path, you enter a target path and then 
nautilus copies the file you right-clicked on to the path you entered.
Shocked the heck out of me when it actually worked. Now, I'd like to 
extend it a bit by checking to see if the file already exists in the 
target dir, and if so give the user the chance to cancel the whole 
operation or overwrite the existing file in the target dir.
Here's what I have come up with so far:

#! /bin/bash
location=`zenity --entry`
question=`zenity --question --text="file "$location/$arg" already 
exists. Do you want to overwrite this file?"`

for arg
do
if [ -e $location/$arg ];then
   read $question     # read the return of zenity --question
    case "$question" in
      0  )  exit 1 ;;     # if user chose "Cancel", then exit
      1  )  cp $arg $location ;;     # if user chose "OK", then copy
    esac
fi
done

What I need to know now is:

1) how to get zenity to give me a directory selection dialog (instead of 
location=`zenity --entry`) so I don't have to type a path into the text 
entry dialog

2) how to capture the o or 1 that zenity --question returns (deternins 
whether the user chose "OK" or "Cancel" in the zenity --question 
messagebox) and then have a seperate action occur depending on whether 
the user chose "OK" or "Cancel". So, I need to learn the proper way to 
use the "case" in the if/then statement above. Any ideas on either of these?

By the way, when this is done, I plan to write a few more scripts and 
make them available to everyone.. possibly get them added to the 
nautilus file manager - I hope.

Ian MacGregor




More information about the users mailing list