I found a script on another website which accessed the Faces information in iPhoto. After digging through the database formats and making considerable changes, I have produced this version which allows you to view information on any number of selected photos, and/or obtain a full list of face information in your current database. This ability could be useful in any number of situations where you want to obtain the Face data. For example, I want to create a website that not only allows people to browse by photo, but also by the people in the photos.
-- Get Aperture Face Names
-- © 2012, Tim Doyle
-- Based on mr. applescript's iPhoto script, posted at http://hints.macworld.com/article.php?story=20090302060210294
tell application "Aperture"
activate
set the selected_items to the selection
repeat with z from 1 to the number of items in selected_items
set this_photo to item z of selected_items
set the query_results to my extract_face_record(this_photo)
if the the query_results is not false then
set AppleScript's text item delimiters to return
repeat with i from 1 to the count of the query_results
set the info_list to item i of the query_results
if i is 1 then
set the dialog_text to the info_list as rich text
else
set the dialog_text to the dialog_text & return & the info_list as rich text
end if
end repeat
set AppleScript's text item delimiters to ""
display dialog dialog_text
end if
end repeat
--select selected_items
end tell
-- Get and display the names of all Faces in the current Library
set the face_names to my get_all_faces()
repeat with z from 1 to the number of items in face_names
set this_face to item z of face_names
if z is 1 then
set the dialog_text to this_face
else
set the dialog_text to the dialog_text & return & this_face
end if
end repeat
tell application "Aperture"
display dialog dialog_text
end tell
on extract_face_record(this_photo)
set Aperture_library_path to do shell script "defaults read com.apple.Aperture LibraryPath"
-- expand the '~' if it's in there
set Aperture_library_path to do shell script "echo " & Aperture_library_path
if Aperture_library_path does not end with "/" then
set Aperture_library_path to Aperture_library_path & "/"
end if
set the Faces_database_path to Aperture_library_path & "Database/apdb/faces.db"
set the Aperture_database_path to Aperture_library_path & "Database/apdb/Library.apdb"
-- Get the UUID for this photo version
set the photoID to the id of this_photo
-- Look up the UUID for the master of this version
set the masterID to my SQL_command(Aperture_database_path, "select masterUuid from RKVersion where uuid=\"" & photoID & "\";")
-- Look up the face keys for all faces in this master photo, list them from left to right
set the face_keys to every paragraph of (my SQL_command(Faces_database_path, "select faceKey from RKDetectedFace where masterUuid=\"" & masterID & "\" AND rejected=0 AND ignore=0 ORDER BY topLeftX;"))
-- create a list for each face {short name, full name, email address}
set the face_records to {}
repeat with this_key in the face_keys
set this_face_info to {}
-- get name
set the short_name to my SQL_command(Faces_database_path, "select name from RKFaceName where faceKey=\"" & this_key & "\";")
if short_name is "" then
set short_name to "unnamed"
end if
set the end of this_face_info to the short_name
-- Additional fields, if desired
-- get full name
-- set the full_name to my SQL_command(Faces_database_path, "select fullName from RKFaceName where faceKey=\"" & this_key & "\";")
-- set the end of this_face_info to the full_name
-- get email address
-- set this_email to my SQL_command(Faces_database_path, "select email from RKFaceName where faceKey=\"" & this_key & "\";")
-- set the end of this_face_info to this_email
set the end of face_records to this_face_info
end repeat
return face_records
end extract_face_record
on get_all_faces()
-- Get the names of all faces in this database
set Aperture_library_path to do shell script "defaults read com.apple.Aperture LibraryPath"
-- expand the '~' if it's in there
set Aperture_library_path to do shell script "echo " & Aperture_library_path
if Aperture_library_path does not end with "/" then
set Aperture_library_path to Aperture_library_path & "/"
end if
set the Faces_database_path to Aperture_library_path & "Database/apdb/faces.db"
set the face_names to every paragraph of (my SQL_command(Faces_database_path, "select name from RKFaceName ORDER BY name;"))
end get_all_faces
on SQL_command(database_path, command_string)
return (do shell script "sqlite3 " & (quoted form of database_path) & " '" & command_string & "'")
end SQL_command
Tim,
Thanks for posting this. So what is the result? It pulls the faces data and does what with it?
@PhotoJoseph
— Have you signed up for the mailing list?
Currently, the script calls the routine to grab the face data and once returned, displays that data in a dialog. However, the results of the routine could be used in other ways as well.
The example of what I am going to use this for next is to enhance the current web export to include a view of photos in a collection by individual - similar to the Faces view in Aperture.
Tim,
Very cool. I’d love to see what you do with it (the “faces” view on the web). Please be sure to share the results here!
@PhotoJoseph
— Have you signed up for the mailing list?