Skip navigation

Script to create smart albums from keywords.

570 Views 15 Replies Latest reply: Jul 12, 2013 3:22 AM by léonie RSS
1 2 Previous Next
bdresch Calculating status...
Currently Being Moderated
Jul 8, 2013 10:32 AM

I just brought in 22000 photos from PSE with maybe 150 keyword tags. I'd like to create a smart album for each tag. I found this script in a thread from 2011. It appears that it doesn't work in ML. Anyone know what I need to change to get it to run?

 

 

*tell application "iPhoto"*

*   set allTheKeywords to {}*

*   repeat with thisPhoto in photos*

*      repeat with thisKeyword in keywords of thisPhoto*

*         if name of thisKeyword is not in allTheKeywords then*

*            copy name of thisKeyword to the end of allTheKeywords*

*         end if*

*      end repeat*

*   end repeat*

   activate

*   repeat with thisKeyword in allTheKeywords*

*      if not (album thisKeyword exists) then*

*         tell application "System Events" to tell process "iPhoto"*

*            keystroke "n" using {option down, command down}* -- New Smart Album…

*            keystroke thisKeyword* -- Smart Album name

*            tell group 1 of sheet 1 of window 1*

*               click pop up button 1*

*               keystroke "Keyword" & return*

*               click pop up button 1 of group 2*

*               keystroke "is" & return*

*               click pop up button 1 of group 1*

*               keystroke thisKeyword & return*

*               keystroke return* -- OK

*            end tell*

*         end tell*

*      end if*

*   end repeat*

*end tell*

 

 

https://discussions.apple.com/thread/2708951?start=0&tstart=0

MacBook Pro with Retina display, OS X Mountain Lion (10.8.4)
  • léonie Level 8 Level 8 (46,330 points)
    Currently Being Moderated
    Jul 8, 2013 11:01 AM (in response to bdresch)

    That script works very well for me with  OS X Mountain Lion (10.8.4)  and iPhoto 9.4.3.

     

    Have you removed all the "*" characters? And enabled "Enable Access for assistive devices" in the Accesibility preferences? The script uses GUI scripting and without this option enabled GUI scripting is not possible:

    Screen Shot 2013-07-08 at 19.57.20MESZ.PNG  

     

    tell application "iPhoto"

              set allTheKeywords to {}

              repeat with thisPhoto in photos

                        repeat with thisKeyword in keywords of thisPhoto

                                  if name of thisKeyword is not in allTheKeywords then

                                            copy name of thisKeyword to the end of allTheKeywords

                                  end if

                        end repeat

              end repeat

      activate

              repeat with thisKeyword in allTheKeywords

                        if not (album thisKeyword exists) then

                                  tell application "System Events" to tell process "iPhoto"

      keystroke "n" using {option down, command down} -- New Smart Album…

      keystroke thisKeyword -- Smart Album name

                                            tell group 1 of sheet 1 of window 1

      click pop up button 1

                                                      keystroke "Keyword" & return

      click pop up button 1 of group 2

                                                      keystroke "is" & return

      click pop up button 1 of group 1

      keystroke thisKeyword & return

      keystroke return -- OK

                                            end tell

                                  end tell

                        end if

              end repeat

    end tell

     

    Screen Shot 2013-07-08 at 20.00.45MESZ.PNG

  • léonie Level 8 Level 8 (46,330 points)
    Currently Being Moderated
    Jul 8, 2013 1:37 PM (in response to bdresch)
    Dispatch queue: com.apple.Aperture.RKQueryResultMgr

     

    I'm puzzled by the line above - is your library an Aperture library?

     

    The script crashes with a fatal error, when it is reading the database file inside your iPhoto Library; this could be caused by a corruption in your iPhoto library. I'd try the script first on a simply test library. Create a new library, import a few photos, and tag them with keywords for testing. Does the script run then?

     

    In any case I'd run the First Aid tools on yoir iPhoto library and repair it. The crashed script may have left your library in an inconsistent state.

    To launch in First Aid Mode, hold down the key combination ⌥⌘ firmly and double click the iPhoto library to open iPhoto. Select "Repair ddatabase" from the panel.

     

    Regards

    Léonie

     

    And I would not run an untried script on my main library anyway, without testing it thoroughly on a test library.

  • léonie Level 8 Level 8 (46,330 points)
    Currently Being Moderated
    Jul 8, 2013 10:44 PM (in response to bdresch)

    The script is running out of memory :

     

    Application Specific Information:

    *** Terminating app due to uncaught exception 'NSMallocException', reason: '*** attempt to create a temporary id buffer of length (24736) failed'

     

    Can you tell by the new smart album, that already ghave been added to your iPhoto library, how far the script got, and what the last photo or keyword has been, that has been processed? Perhaps there are illegal characters in the keywords? Do your keywords contain "white space" or ethnic characters?

  • léonie Level 8 Level 8 (46,330 points)
    Currently Being Moderated
    Jul 9, 2013 8:10 AM (in response to bdresch)

    'white space' are characters, that print as white, like spaces, tabs, return, linefeed.

    If I comment out from "activate" down and try to get just the first loop to run, is there any way to see the output of allTheKeywords?

    You could simply   add a "return allTheKeywords" to your script.

     

    Insert right after the second "end repeat"

     

    tell application "iPhoto"

              set allTheKeywords to {}

              repeat with thisPhoto in photos

                        repeat with thisKeyword in keywords of thisPhoto

                                  if name of thisKeyword is not in allTheKeywords then

                                            copy name of thisKeyword to the end of allTheKeywords

                                  end if

                        end repeat

              end repeat

              return allTheKeywords

    end tell

     

    Then you will see the list of keywords in the "Results" tab:

     

    Screen Shot 2013-07-09 at 17.09.23.png


  • léonie Level 8 Level 8 (46,330 points)
    Currently Being Moderated
    Jul 9, 2013 10:10 AM (in response to bdresch)

    Spces in the keywords do not seem to matter. I just tested with these keywords: Even an  in the keyword name does not crash the script.

     

    {"Europe", "flower", "Leonie", "island", "blume", "Photo Stream", "flower digit", "key with", "Turte", "Back", "soon", "We'll be"}

  • léonie Level 8 Level 8 (46,330 points)
    Currently Being Moderated
    Jul 10, 2013 2:31 AM (in response to bdresch)

    You said you repaired your library - have you tried rebuilding and repairing permissions?

     

     

    You could also try to create partial libraries with iPhoto Library manager and split your libray into two halfs for testing: iPhoto Library manager will let you create new libraries from selected event. If you have enough disk space, maybe on a different drive, you then can test, if it is the script or your library.

     

    Or if you do not have the paid version of IPL, simply copy your library to a different drive and delete half of the events from the copy.

1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.