• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to add keywords to photos in iPhoto?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add keywords to photos in iPhoto?


  • Subject: Re: How to add keywords to photos in iPhoto?
  • From: Bill Cheeseman <email@hidden>
  • Date: Sat, 06 Dec 2008 05:05:01 -0500
  • Thread-topic: How to add keywords to photos in iPhoto?

on 2008-12-06 1:30 AM, Dalmazio Brisinda at email@hidden wrote:

> does anyone know of a way to programmatically
> create keywords prior to attempting to assign them?

You have to use GUI Scripting to control iPhoto's user interface, and turn
on the "Enable access for assistive devices" setting in the Universal Access
pane of System Preferences.

Apologies for the length of the example below. Note that I haven't used it
in the last few months, so changes in very recent versions of iPhoto might
have introduced problems.

-- Add Keyword to Selected Photos
-- Version 1.0 Bill Cheeseman 2007-12-30

tell application "iPhoto"
    activate
    display dialog "Enter a keyword to add to the selected photos." default
answer ""
    set theKeyword to text returned of result
    if theKeyword is "" then return

    -- Use GUI Scripting to add new keyword to iPhoto application. iPhoto
can only assign existing keywords to photos.
    set existingKeywords to name of every keyword
    if existingKeywords does not contain theKeyword then
        my openEditKeywordsPanel()
        my addKeywordToIPhoto(theKeyword)
        my closeEditKeywordsPanel()
    end if

    -- Add new keyword to each selected photo in iPhoto.
    set selectedItems to selection
    repeat with thisPhoto in selectedItems
        if class of thisPhoto is photo then
            if name of keywords of thisPhoto does not contain theKeyword
then
                select thisPhoto
                assign keyword string theKeyword -- to selected photo
            end if
        end if
    end repeat
end tell

on openEditKeywordsPanel()
    activate application "iPhoto"
    tell application "System Events"
        tell process "iPhoto"
            get title of menu item 4 of menu "Window" of menu bar item
"Window" of menu bar 1
            if result starts with "Show" then keystroke "k" using {command
down}
            if button "Edit Keywords" of front window exists then click
button "Edit Keywords" of front window
        end tell
    end tell
end openEditKeywordsPanel

on addKeywordToIPhoto(thisKeyword)
    activate application "iPhoto"
    tell application "System Events"
        tell process "iPhoto"
            if (button 6 of front window exists) and (help of button 6 of
front window starts with "Create") then
                click button 6 of front window -- "+" button
                perform action "AXRaise" of front window
                keystroke thisKeyword
                keystroke return
                click button "Shortcut" of front window
                key code 51 -- delete automatic shortcut
                keystroke return
            end if
        end tell
    end tell
end addKeywordToIPhoto

on closeEditKeywordsPanel()
    activate application "iPhoto"
    tell application "System Events"
        tell process "iPhoto"
            if button "OK" of front window exists then click button "OK" of
front window
            get title of menu item 4 of menu "Window" of menu bar item
"Window" of menu bar 1
            if result starts with "Hide" then keystroke "k" using {command
down}
        end tell
    end tell
end closeEditKeywordsPanel

--

Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com

PreFab Software - www.prefabsoftware.com


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to add keywords to photos in iPhoto?
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Re: How to add keywords to photos in iPhoto? (From: Dalmazio Brisinda <email@hidden>)

  • Prev by Date: Re: How to add keywords to photos in iPhoto?
  • Next by Date: Re: Sequential renumbering in InDesign CS3
  • Previous by thread: Re: How to add keywords to photos in iPhoto?
  • Next by thread: Re: How to add keywords to photos in iPhoto?
  • Index(es):
    • Date
    • Thread