Monday, 11 July 2011

Auto-prompting "yes" in a shell script

Recently, I made a posting about extracting photos from your iPhone. This is great but what if you have already done this and after a few days, you want to copy the new photos into the same location? Do you delete all your old photos and then re-transfer all of them? Do you look up the photo numbers and specify which numbers to copy over? The first one is easy but more time-consuming and the second one is tedious and involves a lot of work. The ideal situation would be to just skip the ones already there and copy over only the new ones. But unfortunately, gphoto2 does not allow this. For every photograph that already exists, you have only the option of overwriting the photo or not. And what's worse - you are prompted for every photo:

File IMG_1107.JPG exists. Overwrite? [y|n] Saving file as IMG_1107.JPG
Downloading 'IMG_1108.JPG' from folder '/store_00010001/DCIM/800AAAAA'...
File IMG_1108.JPG exists. Overwrite? [y|n] Saving file as IMG_1108.JPG

What's the solution? Automate the process by writing a shell script. The script should be written in such a way that every time the prompt appears, a 'y' is given as input. For this, we will use the immensely useful yes utility. Here's the script:

#!/bin/bash

cd /path/to/photos #location of iPhone photos
yes | gphoto2 --port=usb -R -P
cd - #change back to previous location

No comments:

Post a Comment