Returning part of a record in a list

Hi everyone,

I have a script that returns a list of the exif info of an image, and I am trying to extract the “exif type:artist” information from that list as text that I can then use to add a credit automatically to the image file itself. What I’m having a problem with is actually extracting the information from the record itself, as I’m admittedly still pretty new to Applescripting.

Based on the structure of the list below, would any of you guys have an idea how I can call that record up?

Thanks!

{{exif type:info, exif unicode:"Picture 015"}, {exif type:software, exif unicode:"Adobe Photoshop CS2 Macintosh"}, {exif type:exif creation date, exif unicode:"2007:06:28 13:54:43"}, {exif type:artist, exif unicode:"Robert Thomas"}, {exif type:orientation, exif int:1, exif unicode:"Normal"}, {exif type:comment, exif unicode:"Picture 015"}}

Hi,

assuming the target application is iMagine Photo, you need a repeat loop to filter the data

tell application "iMagine Photo"
	set theList to {{exif type:info, exif unicode:"Picture 015"}, {exif type:software, exif unicode:"Adobe Photoshop CS2 Macintosh"}, {exif type:exif creation date, exif unicode:"2007:06:28 13:54:43"}, {exif type:artist, exif unicode:"Robert Thomas"}, {exif type:orientation, exif int:1, exif unicode:"Normal"}, {exif type:comment, exif unicode:"Picture 015"}}
	repeat with i in theList
		if exif type of i is artist then
			set theArtist to exif unicode of i
			exit repeat
		end if
	end repeat
end tell
theArtist

You can also get the data with the shell command sips


set theImage to POSIX path of (choose file)
set theArtist to text 2 thru -1 of (do shell script "sips -g artist " & quoted form of theImage & " | grep artist | cut -d ':' -f 2")

Beautiful! Thank you so much, this is exactly what I needed!

Do a lot of people use iMagine Photo in here? I’m using it to write a big batching application for my employer… so far things have been working out very well, but occasionally I’ll hit a snag that isn’t answered explicitly in the documentation… it would be amazing to bounce some of those problems off the minds in here.

Thanks again!

Hi,

I am no longer updating iMagine Photo, and was a bit nervous when Leopard came out that it would be broken but it still seems to work ok. I wouldn’t recommend it for new work. If you can’t find a replacement for what you need to do then and you need support I can still be e-mailed at the address: support [at] yvs.eu.com

I have a few routines that I use for getting specific exif info out of the list of exif data. I include them below with an example of how to use one of them.


on GetExifRealFromExifType(exifType, exifData)
	using terms from application "iMagine Photo"
		repeat with theItem in exifData
			if the exif type of theItem is equal to exifType then
				return exif float of theItem
			end if
		end repeat
	end using terms from
	return -1.0E-99
end GetExifRealFromExifType

on GetExifUnicodeFromExifType(exifType, exifData)
	using terms from application "iMagine Photo"
		repeat with theItem in exifData
			if the exif type of theItem is equal to exifType then
				return exif unicode of theItem
			end if
		end repeat
	end using terms from
	return ""
end GetExifUnicodeFromExifType

on GetExifIntFromExifType(exifType, exifData)
	using terms from application "iMagine Photo"
		repeat with theItem in exifData
			if the exif type of theItem is equal to exifType then
				return exif int of theItem
			end if
		end repeat
	end using terms from
	return -32767
end GetExifIntFromExifType

--To get the exposure time from the exif data you would use the GetExifRealFromExifType like so:
using terms from application "iMagine Photo"
	-- exifData is the exif data returned from a line like:
	-- set exifData to the exif data of thisImporter
	set exposureTime to GetExifRealFromExifType(exposure time in seconds, exifData)
end using terms from

These scripts actually came from the page in the documentation on the iMagine Photo website:
http://www.yvs.eu.com/documentation/scripts.html

Kevin