importing photos in gnome

Thanks to HAL, dbus, and the whole alphabet soup, we can execute a script when we plug in our digital camera. The default, running f-spot, doesn’t really do much good. It doesn’t accomplish what it should, namely moving all the files from the camera to our hard drive. Here’s a script I wrote that will actually do that, and it even has a progress bar! It will also create new directories if you import multiple rounds of photos, to prevent overwriting of images. Note that you need zenity in order for this to work.

#!/bin/sh

#change photo_root to the place where all the image directories should go
#change camera_mount to the directory where the camera gets mounted
#change the end of camera_dir to indicate where the photos lie on your flash card
#change dirname to some expression that outputs what you'd like your directories to be called
#  default is YYMMDD

photo_root="/home/owen/Documents/images/photos/raw/"
camera_mount="/media/NO_NAME"
camera_dir=$camera_mount"/dcim/101olymp/"
dirname=`date +%y%m%d`

if type 'zenity' 1>/dev/null 2>&1 ; then
        echo fine
else
        echo We need zenity
        exit 1
fi

if [ `df |grep $camera_mount |wc -l` == "0" ] ; then
	zenity --error --text="Camera not mounted, exiting"
	exit 1
fi
new_dir_made=0
suffix_val=0
new_dir="fart"
while [ $new_dir_made = 0 ] ; do
	if [ -d "$photo_root"$dirname"-"$suffix_val ] ; then
		let suffix_val=suffix_val+1
	else
		mkdir "$photo_root"$dirname"-"$suffix_val
		new_dir="$photo_root"$dirname"-"$suffix_val
		new_dir_made=1
	fi
done

if [ ! -d $new_dir ] ; then
	zenity --error --text="Couldn't create new dir"
	exit 1
elif [ $new_dir = "fart" ] ; then
	zenity --error --text="Couldn't create new dir"
	exit 1
fi

file_count=`ls -1 $camera_dir | wc -l`
i=0
(
for file in $camera_dir/* ; do
	let value=i*100/file_count
	echo $value
	mv $file $new_dir
	let i=i+1
	sleep 1
done
echo "100"
) |
zenity --progress \
          --title="Importing images" \
          --text="Moving images to hard drive..." \
          --percentage=0 \
          --auto-close
umount $camera_mount
nautilus $new_dir
Share