1

I posted this on raspberrypi.stackexchange but was directed here. I'm new to Linux / Unix, and I'm trying to get a tether / display script going with gphoto2.

gphoto2 --capture-tethered --hook-script=myhookscript.sh \
    --filename="/home/media/usbpendrive/image-%Y%m%d-%H%M%S.jpg" \
    --force-overwrite

This is supposed to download the image to my USB pen drive and then look for new commands in the hookscript.

The next stage would be to use qiv or similar image viewer to look for the last capture in the folder, then display it full screen. I would like someone to explain in simple terms how to make this hook script.

2
2

Gphoto passes $ACTION and $ARGUMENT to the hook script, which you can use.

As an example:-

#!/bin/bash

if [ $ARGUMENT ]; then
    if [[ $ARGUMENT =~ .+\.[jpg|JPG] ]]
    then
    # Then next few lines are optional
    # Alternatively pass $ARGUMENT directly to your image viewer eg:-
    # /usr/bin/shotwell "$ARGUMENT" &
    DIRNAME=$(dirname "$ARGUMENT")
    BASENAME=$(basename "$ARGUMENT")
    NEWFILENAME="$DIRNAME/my_new_folder/$BASENAME"
    mv "$ARGUMENT" "$NEWFILENAME"
            /usr/bin/shotwell "$NEWFILENAME" &
    fi
fi

This opens the file in shotwell, but that's easy to change to your preferred viewer.

The second if statement makes sure that shotwell is only used if the downloaded file is a JPG as I sometimes had the camera set to create raw (CR2 on a Canon) which wouldn't open in shotwell. I suppose it could be expanded to to open those with another viewer.

The image will be saved as the argument supplied to --filename - in your case /home/media/usbpendrive/image-20140616-125500.jpg. That will be the value stored in $ARGUMENT and passed to your hook script.

You could use dirname and basename to split this path and filename to their relevant parts and then re-use them to create a new path and filename for the image.

$dirname /home/media/usbpendrive/image-20140616-125500.jpg
/home/media/usbpendrive 
$basename /home/media/usbpendrive/image-20140616-125500.jpg
image-20140616-125500.jpg

$ARGUMENT is only available when gphoto is downloading the image, so a check of $ACTION would be redundant in this case.

The file will need to have it's executable bit set, of course.

I only stopped using this when I found Entangle but I'm not sure that's available on the Pi.

3
  • Thanks for the suggestion; I will try it later on. Entangle is available for the RPI through a Jessie upgrade, but there are a few bugs in it and I haven't quite got it running yet (or maybe it's just me), which is why I went back to the scripting side. How would I put argument in the code to save the images to a folder before they are displayed? – user15163 Jun 16 '14 at 7:56
  • This has been incredibly helpful - thank you. I now want to put more $ARGUMENT in to further expand on what this currently does. QIV is my choice of image viewer, and coupled with --fullscreen I now have an image displayed. I just need to work out a SLEEP 10 before I initialise a shuffled slideshow --shuffle – user15163 Jun 17 '14 at 20:41
  • If you're after a 10 second delay before starting QIV then enter sleep 10s on a line by itself just before you call qiv --fullscreen --shuffle. Type man sleep for more info on the sleep command. – garethTheRed Jun 17 '14 at 20:53

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.