Folder Actions and Pictures

DanBri,

you were looking on a way to use Folder Actions[1] on Macintosh to 
automatically create things.

An example with Photos:

======= cut =======
on adding folder items to this_folder after receiving these_items

-- Here I'm setting in the variable this_name
-- the full unix path of the folder
-- ex: /Users/karl/Pictures/PowershotG2
	tell application "Finder"
		set folder_path to the name of POSIX path of this_folder
	end tell

-- Your shell script is call here

     do shell script "/Users/karl/bin/datephoto.sh " & folder_path


   on error error_message number error_number
     if the error_number is not -128 then
       tell application "Finder"
         activate
         display dialog error_message buttons {"Cancel"} default button 
1 giving up after 120
       end tell
     end if
   end try
end adding folder items to
========== cut =======

For example my shell script can be:

====== cut =====
#!/bin/bash
# datedphoto.sh
# 2004 (GPL)
# Updated by Karl Dubost
# Inspired by Stephanie Troeth's script
###

# We expect one argument only

if [ $# != 1 ]; then
	echo ""
	echo "Usage: datedphoto.sh <root-dir>"
	echo ""
	echo "This program:-"
	echo "  * put pictures in dated space"
	exit 1	
fi

rootdir=$1

##
# testing if epinfo is here first
#
if [ ! -f /usr/local/bin/epinfo ]; then
	echo "You should install epinfo first"
	echo "See http://www.lightner.net/lightner/bruce/photopc/epinfo.html"
	exit -1
else
	echo "Yeah"
fi

# Working on Pictures

list=`find $1 -iname "*.JPG" -print`

for file in $list
{
	echo "Touching $file"

	datepath=`epinfo $file | grep DateTimeOriginal | sed 
's/DateTimeOriginal=//g;s/"//g;' | awk '{print $1}'|sed 's/:/\//g'`

	phototime=`epinfo $file | grep DateTimeOriginal | sed 
's/DateTimeOriginal=//g;s/"//g;' | awk '{print $2}'|sed 's/:/-/g'`

	mkdir -p "$HOME/Pictures/$datepath/"
	filename="$HOME/Pictures/$datepath/pic$phototime.jpg"
	echo "move to $filename"
# dangerous, should I do a savy system?
	mv $file $filename
		
}
======== cut ===========



[1] 
http://rdfig.xmlhack.com/2003/12/05/2003-12-05.html#1070619995.972740
[2] http://www.apple.com/applescript/folderactions/

-- 
Karl Dubost - http://www.w3.org/People/karl/
W3C Conformance Manager
*** Be Strict To Be Cool ***

Received on Thursday, 15 January 2004 18:34:11 UTC