You are here

3 posts / 0 new
Last post
Getting the full keyword list #1
Alex Laske's picture
by Alex Laske
May 27, 2011 - 6:24pm

Hi everyone,

recently I have been facing another problem with Applescript. I wrote a little script that automatically adds the format of a picture to the keywords. It works fine, but it does not use the existing keywords. For example, the script determines a picture to be in landscape. It does not take the keyword “Landscape” out of the list, but instead creates a new keyword at top level and thus creates a duplicate. So I am wondering if there is a way to find out if that keyword already exists; something like: get the name of every keyword of library 1. The problem seems to be that keywords in AS are always contained by image versions. So if I want to get'em all I'd have to cycle through all my photos, which, of course, is not an option. I hope someone can help me.

Thanks in advance.

Alex

Tim Doyle's picture
by Tim Doyle
July 23, 2011 - 1:57am

In one of his training videos, Joseph mentions that Aperture keeps a hierarchical keyword structure internally, but that this structure apparently is not handled properly when dealing with external editor plug-ins. I suspect the same thing is happening here. It may be that Applescript allows you to set keywords, but only at the highest level, which is exactly the behavior you’re seeing. I’ve reviewed the Aperture Applescript documentation, and I do not see a way to obtain the full keyword list.

Mitchell Model's picture
by Mitchell Model
September 24, 2011 - 12:42pm

I’m not sure what exactly you are trying to do, but if your problem is that the keyword Landscape is not at the top level, then your script must add a keyword that reflects the keyword’s parents all the way to the top. Here’s a handler that does that, with lots of explanatory comments:

(*
Mitchell L Model, mlm@acm.org, 2011-09-23

This handler adds a keyword to an image. To add the
keyword to all the selected images, do the usual loop
for selections:

tell app "Aperture"
set theSelectedImages to selection
repeat with n from 1 to the count of theSelectedImages
my addKeyword(item n of theSelectedImages, theKeywordID)
end repeat
end

theKeywordID is the full path from the keyword up to the topmost
parent, with each parent preceded by a tab, which Aperture calls
the id. For example, a keyword Mountains with parent Landscape
with parent Scene has the id "Mountains\tLandscape\tScene".

As far as I can tell, the name and parents properties are
redundant since they can be derived from the id.

"Make new" adds the keyword (and any parents that don't
exist) to the internal list of known keywords if it isn't already
there, which you can then see in the keyword HUD. You can
make a keyword with the same id repeatedly without its being
duplicated in Aperture's keyword hierarchy.

The Aperture AppleScript dictionary does not provide access
to however the application is storing keywords internally, so there is
apparently no way to find out all the keywords without getting the
keyword of every image in the library. (There is, however, one oddity:
if you get the same keyword from each of two images, they are not equal
even though their properties have the same values, something I don't
understand. So, if you want to make a list of all the keywords of a
list of images, compare the ids of the keywords, not the keywords
themselves.

*)

to addKeyword(theImage, theKeywordID)
tell application "Aperture"
set tabpos to the offset of tab in theKeywordID
if tabpos = 0 then
set theName to theKeywordID
set theParents to ""
else
set theName to text 1 thru (tabpos - 1) of theKeywordID
set theParents to text (tabpos + 1) thru length of theKeywordID
end if
tell theImage to make new keyword with properties ¬
{id:theKeywordID, name:theName, parents:theParents}
end tell
end addKeyword

You may login with either your assigned username or your e-mail address.
Passwords are case-sensitive - Forgot your password?
randomness