0

I wrote a bash script (here) for extracting EXIF GPS coordinates from an image and displaying those coordinates as a pointer in Google Maps. It works perfectly when used like this in the terminal:

GUI=1 ./show_location_in_chrome.sh /path/to/image.jpg

I have added a right-click command to Nautilus using Nautilus-Actions with these settings:

           Path: GUI=1 /home/tomas/show_location_in_chrome.sh
     Parameters: %f
Basename filter: *.jpg

But when I right-click a JPEG file and click the menu item, nothing happens. The only exception is when the "Execution mode" is set to "Display output", in which case the script works as intended. Unfortunately Nautilus also displays a large window with script output that I have to manually close every time.

How do I figure out why the script doesn't work in any other execution mode than "Display output"? Please comment if I can provide any more specific information.

The "Run command" displayed in the command output is:

/bin/sh -c 'GUI=1 /home/tomas/show_location_in_chrome.sh '\''/home/tomas/Dropbox/Camera Up
loads/2013-07-21 14.58.33.jpg'\'''

Edit: I have added #!/usr/bin/env bash to the top of my script and removed the explicit call to bash in the "Path" setting. It changed nothing.


Edit: I added echo "Works" > ~/test.txt to the top of the script (below the shebang), then clicked the menu item. No files were added to my Home folder, so I have concluded that the script isn't even being executed when the execution mode is anything other than "Display output".

1

Possibly, with "display output" off, it probably doesn't run the command in a shell, so the GUI=1 syntax isn't parsed as an assignment. If that's the case, changing the command to this should work:

/usr/bin/env GUI=1 /home/tomas/show_location_in_chrome.sh

As an aside, you probably don't need that GUI variable, you can use what is already there to determine whether to use zenity or not. E.g. The DISPLAY variable should only be set if you're logged in graphically, so changing [ "$GUI" ] to [ "$DISPLAY" ] (or better, [[ $DISPLAY ]]) should work fine.

If you only want to use zenity when not running it from a terminal, you can test for a terminal with the -t test. E.g.

if [[ ! -t 1 && $DISPLAY ]]; then   # if fd 1 (stdout) is not connected to a terminal, and DISPLAY is non-empty
    zenity ...
else
    echo ...
fi

EDIT: Alternatively, add an option to specify "gui or not".

gui=0
while [[ $1 = -* ]]; do
    case $1 in
        -h|--help) echo "usage..."; exit ;;
        -g|--gui) gui=1 ;;
         *) echo >&2 "invalid option: $1"; exit 1 ;;
    esac
    shift
done

#...

if (( gui )); then
    zenity ...
else
    echo ...
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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