5

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?

1

2 Answers 2

2

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)

1
  • 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,
    – J D
    Nov 3, 2012 at 18:40
0

Try this as your desktop entry, You may want to add quotes around the %f.

[Desktop Entry]
Exec=/usr/bin/bash %f
Name=Bash
Terminal=false
Type=Application

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .