chronological by exif...

Hello!
I am trying to do something very simple that seems to be very complicated. I want to attach a folder action to a folder full of pictures that will put them in chronological order based on the EXIF data. The view option in OSX that allows you to arrange photos by date created does not work for this. So I want to write or find a simple script that I can attatch to the folder that will arrange the photos in chronological order regardless of what camera they came from.
Any help with this is much appreciated!
~Joe

I had a similar task: rename pictures to their EXIF dates.
Due to missing reliability with EXIF on OS X, I wrote an AppleScript that called a PHP-Script to do the job. → AS app is only GUI . This works faster than with an HTML UI. I assume this is because the AS calls the PHP intepreter directly without touching Apache.

The standard PHP installation includes the vital EXIF-module. (Tiger)
IM me for help with PHP or look on the PHP-forums for more info.

Hi,

I was waiting to see if Apple added something new to the os to read exif, but I guess not. Here’s a post:

http://bbs.applescript.net/viewtopic.php?pid=66812

Here’s Imagine Photo:

http://www.yvs.eu.com/imagine.html

You want the capture date I think.

http://www.yvs.eu.com/documentation/index.html

gl,

I was fooling around with this and here’s an example of getting the capture date:


set f to choose file
tell application "iMagine Photo"
	set gi to import graphic f
	set exifd to exif data of gi
	set cd to missing value
	repeat with this_info in exifd
		if exif type of this_info is capture date then
			set cd to exif unicode of this_info
			exit repeat
		end if
	end repeat
	close gi
	quit
end tell
if cd is not missing value then
	set {y, m, d, h, min, s} to words of cd
	set date_string to (m & "/" & d & "/" & y & space & h & ":" & min & ":" & s)
	date date_string
else
	cd
end if

Note that the date of my sample picture had the form “y/m/d” so I had to switch it around to “m/d/y” for my system.

Edited: and btw, I got samples with exif data here:

http://www.exif.org/samples.html

gl,

@ke|: do you process 1000s of images this way? Or are we talking about under 50 images?

Joe, are you willing to rename the images? That or editing the comments are the only ways I can think of to sort the files in the Finder.

Hi Luke,

This script just handles one file without naming. Nobody mention how you want to rename the file, but a scirpt could easily do the job. I don’t know how long it would take to do 50 or 1000. Don’t think I want to download 1000 pictures with exif data. Tell me how you want to rename the file and I’ll show you an example. Note that droplets and folder actions don’t work in Scirpt Editor. It’s best to test scripts with repeat loops first and then convert the script to one of the previous forms.

Edited: just thought of something. There’s no need for 1000 pictures for testing. Just get capture date and rename the same file 1000 times. I’ll try testing it when I have time.

gl,

telling PHP to examine a folder (incl. subfolders) is so snappy, I doubt an AS can beat the speed of *NIX renaming.

But hey, we’re on an AS forum So let’s see how it Can be done without calling another app.

EXIF data is stored in the file and AS has functions to read contents of files. → possible to do this all with AS.

I consider that reinventing the wheel. EXIF was supposed to be a standard, but it isn’t really. Some DC manufacturers have changing EXIF format from one model to the next.

If you want to see how I solved my task and test it’s speed:http://SwissalpS.ws/OSprojects/imgrenPHP/imgren.zip

Hi Luke,

In my test it took approx 1 min, 15 sec for 1000 tries of the same file. This was doen with iMagine Photo already launched. I couldn’t add the actual renaming of the file, because I would have to renam it back to the original name for the next iteration.


-- just getting 1000 item list for testing
set f to choose file
set photo_list to {}
repeat 1000 times
	set end of photo_list to f
end repeat
--set t1 to the ticks -- uses Jon's Commands; doesn't work with Intel machine
-- process photos
repeat with this_photo in photo_list
	-- get capture date
	tell application "iMagine Photo"
		set graphic_ref to import graphic this_photo
		set exif_data to exif data of graphic_ref
		set capture_date to missing value
		repeat with this_info in exif_data
			if exif type of this_info is capture date then
				set capture_date to exif unicode of this_info
				exit repeat
			end if
		end repeat
		close graphic_ref
	end tell
	if capture_date is not missing value then
		-- convert capture date to valid Finder name
		set {y, m, d, h, min, s} to words of capture_date
		set t to ((h * hours) + (min * minutes) + s) as string
		set date_string to m & "/" & d & "/" & y & "-" & t
		-- get base name and extension of this photo and append capture date
		set file_name to name of (info for this_photo)
		set utid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to {"."}
		tell text items of file_name
			set {base_name, this_ext} to {((items 1 thru -2) as string), last item}
		end tell
		set AppleScript's text item delimiters to utid
		set new_name to base_name & "-" & date_string & "." & this_ext
		-- here you would set the name of the photo to the new name
		-- but the time wouldn't be accurate because you would have to change the name
		-- back to the original name for the next loop
	else -- there was no capture date in the exif data
		-- do whatever
	end if
end repeat
--set t2 to the ticks -- end test
--display dialog (t2 - t1)
new_name

– result
→ “nikon-e950-04/06/2001-42700.jpg”

I made the time in seconds which can be easily added back to the date when getting file info. I think I know what you mean about the date format.

gl,

For a “once-a-month-job” that might be fast enough. Thanks ke!.
I’m still wondering whether joe can rename the files or prepend something to the files comment.
Maybe the file names already define an order he needs somewhere else.

Hi Luke,

That’s a very good idea. You could just add the capture date to the beginning of the comments of a file, then set the sort order of the list view options to comments. I like the way you think.

gl,

Something like this droplet:


on open photo_list
	-- process photos
	repeat with this_photo in photo_list
		-- get capture date
		tell application "iMagine Photo"
			set graphic_ref to import graphic this_photo
			set exif_data to exif data of graphic_ref
			set capture_date to missing value
			repeat with this_info in exif_data
				if exif type of this_info is capture date then
					set capture_date to exif unicode of this_info
					exit repeat
				end if
			end repeat
			close graphic_ref
		end tell
		if capture_date is not missing value then
			-- prepend capture date to file's comment
			tell application "Finder"
				set old_comment to comment of this_photo
				set comment of this_photo to (capture_date & return & old_comment)
			end tell
		else -- there was no capture date in the exif data
			-- do whatever
		end if
	end repeat
	tell application "iMagine Photo" to quit
end open

Needs error checking on dropped items.

gl,

Hi kel,

you can do the same thing with the built-in application Image Events

on open theseFiles
	repeat with i in theseFiles
		try
			tell application "Image Events"
				launch
				open i
				tell image 1
					set theDate to (value of 1st metadata tag whose name is "creation")
				end tell
				try
					close image 1
				end try
			end tell
			tell application "Finder"
				if comment of i is "" then
					set comment of i to theDate
				else
					set comment of i to theDate & return & comment of i
				end if
			end tell
		on error
			try
				tell application "Image Events" to close image 1
			end try
		end try
	end repeat
	quit application "Image Events"
end open

Hi Stefan,

Where where you all this time? :slight_smile: I don’t have image events, so didn’t know if Apple added something.

gl,

/System/Library/CoreServices/Image Events.app

Everybody has Image Events :slight_smile:

The Event apps Image Events, DataBase Events and System Events reside in /System/Library/CoreServices/
(as Luke has already mentioned) working in the background without having any GUI

If I recall correctly Kel is X.2 and Image Events was introduced with X.3

Well thanks for the extensive response guys. It sounds like the easiest thing to do is to edit the comments or rename the image files, like Luke suggested. It’s too bad you can’t just tell the finder to locate the EXIF date and sort it by that. So I saw the script that Stefan posted (thanks Stefan!) and am going to use that to edit the comments. Do I just change the “these files” in the first line to the name of the folder?
Thanks again,
~Joe

No, theseFiles is a list of files (of class alias)
You can define the list with

tell application "Finder" to set theseFiles to files of folder "Path:To:Folder:"

then the list is a list of file references not aliases
you probably must change the line open i into open (i as alias)

Hi Stefan,

As Mark said, Image Events was introduced in Panther. However, iMagine Photo can do much more than just getting exif info from pictures and is good to know how to use.

gl,

Of course you’re right,
I thought, in this case only for getting the creation date it’s not necessary to install an extra application :slight_smile: