How to get iPhoto '11 (Version 9 in iLife11) event Names

Hi all,

I am looking for the real event Names in iPhoto, not the event names inside iPhoto Library.

have seen a post with title “How to get iPhoto '08 events” and the answer from Craig:

[i]tell application “iPhoto”
set a to image path of photo 666
end tell

GetEventName(a)

to GetEventName(b)
set astid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “/”
set event_string to b’s text item -2
set AppleScript’s text item delimiters to astid
return event_string
end GetEventName

–>“Jan & Feb 2007”[/i]

This lines are working fine, but shows the event names in the Master Folder of iPhoto only.

Example:
Real visible Name is= “Halloween 2010” and in iPhoto the event name is = “20101102-204841”

My plan is to create folders and sub folders based on the date and sort the events into the folders with the real event name.

Thank you in advance
Peter

It is still not currently possible to get Event names by scripting iPhoto, and as you noticed already, my previous script that involved parsing the original path of an image does not function when the user has generated a unique name for an Event.

The only way to get all the Event names used in an iPhoto library is to parse the AlbumData.xml file. The following script is not pretty, but it does generate a list of all the current iPhoto events in one of my iPhoto libraries:

set iphoto_album_xml to (path to pictures folder as text) & "Cathouse Working:AlbumData.xml"
set read_file to open for access iphoto_album_xml
set all_paras to read read_file
close access read_file
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "<key>RollName</key>"
set all_sections to text items 2 thru -1 of all_paras
set AppleScript's text item delimiters to astid
set event_Names to {}
repeat with a_Roll in all_sections
	set beg_name to (offset of "<string>" in (a_Roll as text)) + 8
	set end_name to (offset of "</string>" in (a_Roll as text)) - 1
	set end of event_Names to ((characters beg_name thru end_name of (a_Roll as text)) as text)
end repeat
-->{"KennelPhotos", "May 3, 2010", "May 11, 2010", "May 14, 2010", "May 16, 2010", "May 16, 2010", "May 18, 2010", "McChord Sky", "May 22, 2010", "May 23, 2010", "May 25, 2010", "May 28, 2010", "May 31, 2010", "Jun 1, 2010", "Federal Way Fly".....}

Interestingly, Events are still called Rolls in the xml file, and this is what each section looks like inside the xml file:

As you can see, you can certainly get the ID numbers of the images in each Event, but you would have to parse another section of the xml file to discover which images those are, so that you can get to the actual files of the photos in each event.

Is this close to what you want?

Thank you very much Craig,
Yes, have found these informations in the XML file already, but my hope was to find a solution with Applescript.
In my daily business I have done such XML extractions/creations several time with Windows Script Host. But that was not as elegant as Applescript.

Now I have a good starting point with your little parsing script.

Will post my results here.

Again, thank you
Peter

PS: Do I have to create a new topic if I want to know how it is possible to create and write to Folder Albums ?

You will always get better replies with new threads than continually building on an older one.

Here what I have scripted based on Craig’s great starting script:

It will find the real name of an event, so I am able to create an album with the name of an event.
Another script is ready to write the flat album structure. There is a script from peterjohndean, Australia
which is using the source event name (not the real event name). But the script is great, so I was able to modify it to use the real event name.

But it is not a good idea to create just 1000 flat albums (I have round 1000 event names)
No I am looking for a way to create and write to Folder Albums.

Meanwhile I want to say thank you for your help, Craig.

PS: I guess there is a lot room for improvement in the script I have posted. :slight_smile:

– ******** IMPORTANT **********************************************************************
– Before you test the script, please backup your iPhoto database.
– And create a test database with Starting iPhoto while pressing and holding Option Key (Alt), then create a new Library.
– Please understand that I am not liable for any damage and lost. You try the script on your own Risk.
–****************************************************************************************

– Update: The Script is taking the information from AlbumData.xml, but this file is not always uptodate.
– If you change manually the Event Name, it is not updated in this file. At least not immediately.

set nDebug to 1

set iphoto_album_xml to (path to pictures folder as text) & “Bibliothek iPhoto Test2:AlbumData.xml”
set read_file to open for access iphoto_album_xml
set all_paras to read read_file
close access read_file
set astid to AppleScript’s text item delimiters
–set AppleScript’s text item delimiters to “RollName”
set AppleScript’s text item delimiters to “RollID”

set all_sections to text items 2 thru -1 of all_paras
set AppleScript’s text item delimiters to astid
set event_Names to {}
set eventID_Names to {}
repeat with a_RollID in all_sections
–display dialog a_RollID as text

-- Find Roll_ID which is equal to Event_ID
set beg_name to (offset of "<integer>" in (a_RollID as text)) + 9
set end_name to (offset of "</integer>" in (a_RollID as text)) - 1
set end of eventID_Names to ((characters beg_name thru end_name of (a_RollID as text)) as text)
--display dialog EventID_Names

-- Find Real Event Name as you see it in iPhoto
set beg_name to (offset of "<string>" in (a_RollID as text)) + 8
set end_name to (offset of "</string>" in (a_RollID as text)) - 1
set end of event_Names to ((characters beg_name thru end_name of (a_RollID as text)) as text)
--display dialog "Roll ID=" & EventID_Names & "  Event Name= " & event_Names
--display dialog "" & EventID_Names & "  " & event_Names

end repeat

set Display_EventAndID to “”

repeat with i from 1 to number of items in event_Names
set a_Event to (item i of event_Names) as string
set a_EventID to (item i of eventID_Names) as string

set Display_EventAndID to Display_EventAndID & a_EventID & "  " & a_Event & linefeed

end repeat
if nDebug is 1 then
–display dialog Display_EventAndID
end if

set astid to AppleScript’s text item delimiters

set AppleScript’s text item delimiters to “Roll”

set all_sections to text items 2 thru -1 of all_paras
set AppleScript’s text item delimiters to astid

set Roll_ID to {}
set EventImagePath to {}

repeat with a_Roll_ID in all_sections

--debug display
--display dialog a_Roll_ID as text

-- go to Roll ID and extract EventName which is used by iPhot to store it, so we have a link from real Event Name to storage Event name
set beg_name to (offset of "<integer>" in (a_Roll_ID as text)) + 9
set end_name to (offset of "</integer>" in (a_Roll_ID as text)) - 1
set end of Roll_ID to ((characters beg_name thru end_name of (a_Roll_ID as text)) as text)

--debug display
--display dialog Roll_ID

set beg_name to (offset of "<key>ThumbPath</key>" in (a_Roll_ID as text)) + 20 + 9
set len_name to length of a_Roll_ID

set end_name to beg_name + (offset of "</string>" in (text beg_name thru len_name of (a_Roll_ID as text))) - 1 - 1

--debug display
--display dialog beg_name
--display dialog end_name

set a_EventImagePath to ((characters beg_name thru end_name of (a_Roll_ID as text)) as text)
--display dialog ((characters beg_name thru end_name of (a_Roll_ID as text)) as text)

-- extract the storage event name from path
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set StorageEventPath to a_EventImagePath's text item -2
set AppleScript's text item delimiters to astid

--display dialog StorageEventPath
set end of EventImagePath to StorageEventPath

end repeat

– remove double entries in event list

set SingleEventList_ID to {}
set SingleEventPathList to {}

repeat with i from 1 to number of items in Roll_ID
set a_Roll_ID to (item i of Roll_ID) as string
set a_EventImagePath to (item i of EventImagePath) as string

if SingleEventList_ID does not contain a_Roll_ID then
	
	set end of SingleEventList_ID to a_Roll_ID
	set end of SingleEventPathList to a_EventImagePath
	
	
end if

--debug display
--display dialog a_Roll_ID & "  " & a_EventImagePath


set display_SingleEvents to ""

end repeat

repeat with i from 1 to number of items in SingleEventList_ID
–(item i of SingleEventList_ID ) as string
–(item i of SingleEventList) as string

--debug display
--display dialog ((item i of SingleEventList_ID) as string) & "  " & ((item i of SingleEventPathList) as string)

set display_SingleEvents to display_SingleEvents & ((item i of SingleEventList_ID) as string) & "  " & ((item i of SingleEventPathList) as string) & linefeed

end repeat

if nDebug is 1 then
–display dialog display_SingleEvents

set display_all to ""
repeat with j from 1 to number of items in eventID_Names
	set nPosition to list_position((item j of eventID_Names), SingleEventList_ID)
	--display dialog nPosition
	set display_all to display_all & ((item nPosition of EventImagePath) as string) & "  " & ((item nPosition of eventID_Names) as string) & "  " & ((item nPosition of event_Names) as string) & linefeed
	
	
end repeat

--display dialog display_all

end if

set question to display dialog “You have " & (number of items in SingleEventList_ID) & " Events in your Library. Are your sure you want to display so many records in a popup message?” buttons {“Yes”, “No”} default button 2
set answer to button returned of question

if answer is equal to “Yes” then

display dialog Display_EventAndID

display dialog display_SingleEvents

display dialog display_all

end if

– List Position Script from: Sal Soghoian/Bill Cheeseman, AppleScript 1-2-3
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end list_position