Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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]

Type=Application

Name=convertpics

Exec='/fullpath_to_script/convertpics.sh'

Terminal=true

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: askubuntu.com/questions/88480/… –  Alistair Buxton Oct 21 '12 at 1:31
add comment

1 Answer 1

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 infoHere.sh in ~/.gnome2/nautilus-scripts/:

#!/bin/bash
echo "\$* = $*" >> info.txt
echo "NAUTILUS_SCRIPT_SELECTED_FILE_PATHS = $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" >> info.txt
echo "NAUTILUS_SCRIPT_CURRENT_URI = $NAUTILUS_SCRIPT_CURRENT_URI" >> 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
add comment

Your Answer

 
discard

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.