If you found your way here, this site has migrated. Go to ApertureExpert.com.
Search ApertureExpert.com

Please Support the Site

I’ve been asked many times how you can support the free tips & tricks, and say “thanks” for the answers in the forums, so I’ve finally added “contribute” buttons to the site. Any and all recurring or one-time contributions are greatly appreciated, and allow me to put more time and energy into ApertureExpert.com! Thank you! 

Most Recent Entries
that's the most recent 100 tips…

Join the Mailing List!

Training on Lynda!

Did you know that many of Joseph’s training videos are now on Lynda.com?

Click here for the listing of all the training, or click below to get a free 7-day trial.

7-day free trial—neat!

Here’s a playlist of the best Aperture and related training on Lynda.com, too.

FREE Live Training!

Join us for our irregularly scheduled bi-weekly FREE Aperture Live Training! When’s the next one? Click here to see!

Creative Adjustments
by Thomas Boyd

Check out these recently re-released training videos by photojournalist Thomas Boyd!

Kitchen Sink Bundle

New to ApertureExpert, and you want it all? Check out the Kitchen Sink Bundle!

All new Aperture Addendum Workshop

Joseph’s new iOS 6 Workshop

Joseph’s iPhoto for iPad Workshop

Joseph’s iMovie for iOS Workshop

Joseph’s Nik Creative Effects Workshop

Joseph’s iBooks Author Workshop

Joseph’s Photography 101 Workshop

Work Like a Pro Photographer in Aperture 3

Joseph’s Final Cut Pro X Workshop

“Looks #2” Adjustment Preset pack

“Split Tone” Adjustment Preset pack

Aperture Inspector—analyze your library

15 Tips on File Management in Aperture 3

In-Depth Getting Started with Aperture 3

Killer Tips… download the first chapter free

« Aperture 3.2 with iCloud support is up on the Mac App Store | Main | Skitch is now free »
Friday
Aug262011

Add Aperture Face Names as Keywords—Within Aperture

I like Apperture Faces but was having trouble getting the names to appear as tags when I uploaded to flickr using FlickrExport.

Below is an AppleScript that adds the names of faces in the photo as keywords.

Based on a script by mr. applescript

This article showed me how to get started with AppleScripts.

Cut and paste this code into a new script called e.g add_face_keywords in your Apperture scripts directory:

(* This script looks in the faces database and gets names of the faces in the selected photos
   If then makes a new keyword with the name (and parent keyword "Face")  *)

tell application "Aperture"
    activate
    -- locate the current aperture library
    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
    -- add trailing slash if necessary
    if aperture_library_path does not end with "/" then
        set aperture_library_path to aperture_library_path & "/"
    end if
    
    -- locate the databases
    set the faces_db_path to aperture_library_path & "Database/apdb/faces.db"
    set the library_db_path to aperture_library_path & "Database/apdb/Library.apdb"
       
    set the selected_items to (get the selection)
       
    repeat with z from 1 to the count of the selected_items
        set this_photo to item z of the selected_items
        my extract_face_record(this_photo, library_db_path, faces_db_path)
    end repeat
end tell

on extract_face_record(this_photo, library_db_path, faces_db_path)
    set the master_uuid to every paragraph of (my SQL_command(library_db_path, "select masterUuid from RKVersion where uuid=\"" & id of this_photo & "\";"))
    --get detected faces for the image key
    set the face_keys to every paragraph of (my SQL_command(faces_db_path, "select faceKey from RKDetectedFace where masteruuid=\"" & master_uuid & "\";"))
    
    -- for each face
    set the face_records to {}
    repeat with this_key in the face_keys
        -- get name. NOTE could select fullName instead of select name if you wished
        set the face_name to my SQL_command(faces_db_path, "select name from rkFaceName where faceKey=\"" & this_key & "\";")
        -- add it as new key word
        tell application "Aperture"
            tell this_photo
                make new keyword with properties {name:face_name, parents:{"Face"}}
            end tell
        end tell
    end repeat
end extract_face_record

on SQL_command(faces_db_path, command_string)
    return (do shell script "sqlite3 " & (quoted form of faces_db_path) & " '" & command_string & "'")
end SQL_command

Reader Comments (5)

Excellent! This is awesome. Thanks! :)

December 6, 2011 | Registered CommenterMichael Ball

hello,
about 'This article showed me how to get started with AppleScripts.'

do you still have the article?

best regards

June 21, 2012 | Registered Commenterpeter shi

That article was on MacCreate which is no more. Try looking for it on the Way Back Machine.

-Joseph @ApertureExpert
Have you signed up for the ApertureExpert mailing list?

June 21, 2012 | Registered CommenterJoseph Linaschke

I understand this is an aperture forum, but I was wondering if you guys could give some pointers on a similar script that copies faces to keywords for iPhoto.. ? That would be extremely useful!!

August 25, 2013 | Registered CommenterApple User

Apple User,

iPhoto does appear to be scriptable [screenshot] so you might be able to take the above script and modify it for your use in iPhoto. Also try posting your question (linking back to this post) in the AppleScript forum.

-Joseph @ApertureExpert
• Have you signed up for the ApertureExpert mailing list?

September 19, 2013 | Registered CommenterJoseph Linaschke
This site is now in read-only mode.
2013-11-13 13:00 PST — ApertureExpert.com is now in READ ONLY mode, as we are in the process of migrating to the new site. No new posts, comments, tips, etc. can be created. Beta will last several days; thank you for your patience during this transition.