Handling multiple iPhoto Libraries via AppleScript

After awhile an iPhoto library and the Pictures folder can get quite cluttered with pictures from many sources. One way that can make this easier to handle is to use multiple libraries to keep things separated. I use three different ones myself. To create a new one or switch between different ones, just hold down the option key while opening iPhoto and a dialog box will prompt you for what you want to do.

However, switching between separate libraries using this method can quickly get to be a pain. I’ve written an AppleScript to help with this. Download the iPhoto Library Launcher, open it in the Script Editor, modify the libraryPath to refer to your library, and then save it. iPhoto won’t allow you to have multiple libraries open simultaneously, though the script should detect if another library is already open. If that’s the case, a dialog box saying “About to quit iPhoto!” will pop up and the user can choose to cancel or continue. If no choice is made within five minutes, the script continues launching the new library.


8 Responses to “Handling multiple iPhoto Libraries via AppleScript”

  1. George C Says:

    Thanks very much for this! Just what I was looking for. Unfortunately, when I run it it pops open the “Library Chooser” window (iPhoto ’09), and I am wondering how to get around that so I can automate some stuff with Hazel.

    Any ideas?

  2. Matthew Says:

    I’m using iPhoto ’08 so something may have changed, though I doubt what’s needed for this script would have changed. The Library Chooser will open whenever the the RootDirectory sibling in the iPhoto plist file is blank or the file it references is not there. Make sure that the libraryPath you specify in the script is valid. You might also try commenting out the line that “Restores the default library.” If that works and you don’t need the default restored, you’re good to go. If you do need it restored, let me know if it worked and we’ll have to go from there.

  3. George C Says:

    Aha, it’s the lack of a default library that was causing the issue. I think it has to do with me not having my main (default) library in the default location — it’s large and I moved it to a partition on an external disk.

    Seems the “restore default library” (which I do want) is getting deleted. I found a script to set the default library to my moved library, but your script must expect it in the default OS X location.

    Your script works perfectly if there is a default library specified (even on the external drive partition), but I lose that default when running your script.

  4. George C Says:

    Also, I am using this path structure as my libraryPath:

    “Volumes:ExtDrive:Photos:_iphoto:iPhoto Library Main”

    Maybe that has something to do with it. I’m an amateur AppleScripter 🙂

  5. Matthew Says:

    Ah yes. It does assume that your main library would be at the default location.

    Try changing to the last do shell script line to two lines like

    set defaultLibraryPath to “Volumes:ExtDrive:Photos:_iphoto:iPhoto Library Main”
    do shell script “defaults write com.apple.iPhoto RootDirectory ” & quoted form of POSIX path of defaultLibraryPath

    You can change the defaultLibraryPath variable to refer to any iPhoto Library you would like and that would be the library that opens up whenever you click the iPhoto application icon.

    Your path looks like it should work. The script takes care of converting it to the needed format with the POSIX stuff.

  6. George C Says:

    That did the trick, thanks so much for your help!

  7. IGottaKnowYouKnow Says:

    I have two Libraries, and I’d like to be able to toggle between them. Basically have a script I can run that will determine which one is open, and close it and open the other one, while leaving the default as it is, incase I go to open iPhoto at work etc. I can leave the default Library as ‘work safe’. Any ideas on how to make that happen?

  8. Matthew Says:

    Following the instructions in the last comment I posted should fix your issue. However, I noticed that in the latest version, (OS or iPhoto, I don’t know which one matters…) that this script seems not to be working. Instead, simply clicking the library you wish to open will open it, but it also changes which one is the default. If you’re running the latest, I would suggest not using the iPhoto application to launch iPhoto and instead simply use the library icons. If that doesn’t work, I’m pretty sure the script could be changed to take care of it. Let me know if you need help with that…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: