Manipulating iPhoto data with Java

Discussion in 'Mac Programming' started by apolson, Dec 2, 2007.

  1. apolson macrumors newbie

    Joined:
    Dec 2, 2007
    #1
    I'm working on a Java-based application that I would like to use to manipulate library data in iPhoto. Short of reverse-engineering the files is there any way to call native iPhoto methods in Java? Specifically I want to be able to automate the addition of photos, adding metadate to photos, creating albums, etc. I was thinking of using JNI to call the methods but I'm not really sure where to go from there.

    I've done several searches but haven't really come up with anything promising. Any help would be greatly appreciated.

    Thanks,
    Alex
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You can use AppleScript to interact with iPhoto. Not sure how you would do that from Java - maybe through a separate process?
     
  3. jeremy.king macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #3
    With NSAppleScript, of course :)

    Does this still exist in Leopard?
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Yes it still exists. Not sure how well it works with Cocoa-Java.
     
  5. hhas macrumors regular

    Joined:
    Oct 15, 2007
    #5
    Bear in mind that the Java-Cocoa bridge has been deprecated since Tiger, so may not be the best choice for new development.

    Anyway, there is an 'AlbumData.xml' plist file in the iPhoto library which may or may not be intended to be third-party readable (although various third-parties read it anyway). There's also an ObjC plugin API, although I'm fairly sure that's undocumented, and probably not quite what the OP's needing anyway. The main (official) API for manipulating iPhoto data is iPhoto's Apple event ['AppleScript'] interface. It's less than stellar as APIs go, being somewhat quirky, buggy and/or deficient in various areas, but can probably be cajoled into doing what's needed.

    Ideally the OP wants a high-level Java-Apple event bridge that would allow Java programs to control 'AppleScriptable' applications directly. Right now no such beast exists, although I am planning to do a port of objc-appscript to Java next year. That may be too long to wait, however, in which case the OP will need to make their own arrangements.

    For simple tasks using osascript to execute prewritten AppleScripts that take string-based arguments may be adequate, but for anything complex you'd probably find yourself having to do code generation which is pretty evil and prone to error.

    From poking around the MRJAdapter source code it does look as if lower-level Apple Event Manager bindings do already exist, although I've not managed to find any other information on these which makes me think they're probably part of an undocumented API. The MRJAdapter developer may know more about this. That said, working directly with the Apple Event Manager API quickly becomes a real chore as it's rather low-level and the resulting code is very verbose.

    Probably the first thing the OP should do is get familiar with AppleScript (Matt Neuburg's 'AppleScript: The Definitive Guide' (2nd edition) is best for this) and scripting iPhoto, and make sure that iPhoto can do everything they want. For more detailed advice and suggestions, we'd need to know more about the planned application and what it needs to do.

    HTH
     
  6. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #6
    The iPhoto library file is just an XML file - AlbumData.xml. You can easily reverse-engineer this and work with it in pure Java.

    If I were you I'd take the opportunity to learn about JAXB. Put an example AlbumData.xml into an XML->XSD convertor (Google for one) and auto-generate the Java classes from the XSD using JAXB (more steps, maybe more complex, but fewer opportunities for error than crafting the classes by hand).
     
  7. apolson thread starter macrumors newbie

    Joined:
    Dec 2, 2007
    #7
    What I aim to do is sync photo information from one source to another. In this specific case I'd like to sync photos, metadata, albums, etc. from PhotoShop Elements to iPhoto. I've reverse engineered the PSE data but wasn't sure how to add data to iPhoto libraries. I suppose at this point I'll give AppleScript a try to see where that takes me.
     

Share This Page