Hent Billeder

af Hans Schou 2012-12-06

sslug.dk/~chlor/hent-billeder/

Hent billeder fra kamera og ned til disk på en nem og hurtig måde.

Teknik

Opsætning KDE

K -> System Settings -> Hardware -> Device Actions -> Add

Output: %f %d %i

2012-12-05T18:26:24	/media/00B8-14F9 /dev/sdb1 /org/freedesktop/UDisks/devices/sdb1

Solid action script

[Desktop Action open]
Exec=/home/hans/bin/hent_billeder %f %d %i
Icon=bball
Name=Hent billder

[Desktop Entry]
Actions=open;
Type=Service
X-KDE-Action-Custom=true
X-KDE-Solid-Predicate=[StorageVolume.usage == 'FileSystem' AND StorageVolume.ignored == 'false']

BASH script: ~/bin/hent_billeder

#! /bin/bash
# by Hans Schou 2004

TODAY=$(date +%F)
BASE=${HOME}/foto/Billeder$(date +%Y)
PHOTO=${BASE}/${TODAY}
SOUND=/usr/share/sounds/Kopete_User_is_Online.ogg

echo -e "$(date +%FT%T)\t$*" >> /tmp/$( basename $0 ).log

if [ -n "$1" ]; then
	DEV="$1"
	echo "Device name is: ${DEV}"
	if [ ! -d "${DEV}" ]; then
		echo "Error: no directory at '${DEV}'"
		exit 1
	fi
else
	echo "Error, no args: missing mount point"
	exit 1
fi

DCIM=${DEV}/DCIM

# Create todays dir if not exist
if [ ! -d ${PHOTO} ]; then
	mkdir -p ${PHOTO}
	echo "Created dir: ${PHOTO}"
fi
# Go dir or exit on error.
cd ${PHOTO} || (echo "Dir not found: ${PHOTO}"; exit)

while [ ! -d "${DCIM}" ]; do
	echo "Waiting for device ready"
	ls ${DCIM}
	sleep 1
done
	
# Start konqueror in back ground to view files while they get downloaded
( konqueror file:${PHOTO}/ & ) &

GQOPEN=0
# Download all fotos
ls ${DCIM}/[1-9][0-9][0-9]*/* ${DCIM}/Camera/* | while read F; do
	cp -v "${F}" "${PHOTO}/"
	[ -e ${PHOTO}/$(basename "${F}") ] && rm -f "${F}"
	if [ $GQOPEN -eq 0 ]; then
		GQOPEN=1
		/usr/bin/geeqie ${PHOTO}/$(basename "${F}") &
	fi
done

echo "Unmounting: '${DEV}'"
umount ${DEV}

play ${SOUND}
kdialog --title "Hent billeder" --passivepopup "Kamera-filer downloadet til '$PHOTO', USB kan tages ud nu" 20

sslug.dk/~chlor/hent-billeder/