Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use this console command to automatically send all files in some directory to the JAR file, catch the output of that JAR file and finally create new files from the output. Here is the command

for i in `find . -type f -name '*xml'`; do java -jar "~/grabbertty.jar" $i > $i.txt; done  

Now, I know how to make nautilus-script which will be called via RightClick->Scripts.

What I do not know is how to convert this command to say "convert all files in currently selected directory". Currently selected directory is a directory where I right click.

Anyone can help. Thanks.

share|improve this question
up vote 2 down vote accepted

This should do the trick for you, comment if something weird comes up

#! /bin/bash
base="`echo $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
     while [ ! -z "$1" -a ! -d "$base/$1" ]; do shift; done

for i in `find "$dir" -type f -name '*xml'`; do java -jar "~/grabbertty.jar" $i > $i.txt; done  

When you right click on a folder it should apply your find inside that folder, if you are not clicking on a folder it should apply your find inside the current folder.

Save it in your "$HOME/.gnome2/nautilus-scripts/<nameofthescript>.sh and make it executable with chmod 755 <nameofthescript>.sh.

share|improve this answer
Did all this, it appears among my other nautilus scripts, but it does not do anything. The original file is still unprocessed and no new file is created. As I cannot start this script from the shell, I cannot post any error message. Any suggestion? – ubuntico Oct 23 '11 at 21:00
Shame on me, miss copied your part (the important one!!!) so it was not working, its fixed. – Bruno Pereira Oct 24 '11 at 12:53
If you want that the i$.txt files are created in the same directory as the original xml file instead of '> $i.txt; done' use '> "$dir/$i.txt; done' on the last line. Use the check to mark the question as answered if this fits your needs, regards. – Bruno Pereira Oct 24 '11 at 12:56
Hi, it still does not work. I have tried both $i.txt and $dir/$i.txt and it does not work. all I got was that the empty file named Check.txt was generated in the same dir. – ubuntico Oct 25 '11 at 9:32
what happens if you to to a folder that contains the xml files and type java -jar "~/grabbertty.jar" nameofoneofthefiles > test.txt, replace <nameofoneofthefiles> with one of your xlm. – Bruno Pereira Oct 25 '11 at 14:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.