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 have a small .sh file which I use to convert batches of picture files. I just copy this little file into the folder and run it to convert all the pictures in the folder. This works great but it bugs me that it brings up the "Run in Terminal/Display/Run" option every time.

I tried creating a .desktop file as seen on other posts, named convertpics.desktop:

[Desktop Entry]





I then set the convertpics.desktop file to executable. Now when I double click the convertpics.desktop (now shown just as convertpics) it does run the script BUT it runs it in my home folder rather than the folder I am in. Is there a way to make it use the current folder as the working folder?

share|improve this question
You can't do this with just a .desktop. However, you could add a context menu item as described here:… – Alistair Buxton Oct 21 '12 at 1:31

Your question is missing an important piece of information: you want the script run from nautilus, right?

Ok, so assuming you want to do the following (which is not exactly what your description says, but it is close enough):

  1. Use nautilus (the file manager) to navigate to a folder.
  2. Right click in that folder and run a script with the current folder as a parameter

Here is how you can do this:

  • Create your script (e.g. in bash) and save it in the folder ~/.gnome2/nautilus-scripts/.
  • In your script, instead of the directory path, use "$PWD"
  • Make the script executable

Then you can navigate into the folder, right click, go to scripts, click on your script and it will run in the current folder.

Example: The script in ~/.gnome2/nautilus-scripts/:

echo "\$* = $*" >> info.txt
echo "PWD = $PWD" >> info.txt

The resulting menu looks like this.

Running this script will output a file called info.txt with the content of the important environment variables that you can use in your script.

More about nautilus scripts here:

Ubuntu Wiki pages

A mailing list entry (where the example script is inspired by)

share|improve this answer
Thanks, that worked great. Not quite what I was trying to do but a better solution, now I don't have to bother copying the .sh file to the folder, just right click. I wasn't sure how to incorporate the $PWD into the script so I just put "cd $PWD" near the top and it worked. Thanks again, – A W Nov 3 '12 at 18:40

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.