Has,
Thanks for the detailed response.
So I'll follow your advice and list instead the AppleScript for what should be a simple removal of photos from a given test slideshow album:
tell application "iPhoto" activate set photoTitleList to {"Image1.jpg", "Image2.jpg", "Image3.jpg", "Image5.jpg"} set photoAlbum to album "Test Slideshow" set photoList to photos of photoAlbum repeat with photoTitle in photoTitleList repeat with thePhoto in photoList set theTitle to title of thePhoto if theTitle is equal to photoTitle as string then remove thePhoto from photoAlbum end if end repeat end repeat end tell
Now, when I compile and run this, always, the first 4 images of the slideshow are removed. The fifth image remains in the slideshow album. And so the images I've specified in the photoTitleList seems to be ignored when actually removing the photo from the photo album. I don't understand this. Is this a bug in iPhoto scriptability support?
Ultimately, though if the problem lies in iPhoto scriptability support then it may not matter which scripting bridge system I use. I.e., if I can't get a program to run in AppleScript, then any scripting bridge framework probably won't be very helpful, will it?
Best, dalmazio
Subject: Re: Can't Remove Photos from iPhoto Slideshow using AppleScript / Scripting Bridge
Dalmazio Brisinda wrote:
I'm having trouble removing a series of images from a slideshow album in iPhoto using both AppleScript and Scripting Bridge.
Note that most folks on this list don't know ObjC, so you'll stand a better chance of getting help if you can post AppleScript code.
I decided that Scripting Bridge is much easier to use, so I will focus on it. [snip code]
Hmm. While it is true that AppleScript is an obfuscated mess, it does at least talk good Apple events. Scripting Bridge is an even more obfuscated mess that talks neither good Apple events nor good Cocoa. Any time you get stuck in SB, I suggest you start by working out a working solution in AppleScript first, and then figure out how to translate it to native syntax from there. From the look of your code, you seem to be expecting the SBElementArray to behave like a regular Cocoa NSMutableArray would, which it won't because it isn't. (Did I mention "obfuscated" already?)
Anyway, while iPhoto's scripting support was unfortunately written by folk who didn't entirely understand how it's meant to be done, adding and removing photos to/from albums does more or less follow the usual Cocoa Scripting approach for adding/removing elements to/from non-master collections [1]:
add <object(s) reference> to <insertion location> remove <object(s) reference> from <object reference>
Using a multi-item reference here (e.g. 'remove (every photo whose name is in namesList)...') proves to be a big bag of fail, so you'll need to remove each photo individually, e.g.:
repeat with theName in {"img - 1", "img - 4", "img - 6", "img - 8"} tell application "iPhoto" remove (photo theName of album "test") from album "test" end tell end repeat
I won't bother figuring out the SB equivalent as its whack-a-mole API always annoys me, but you should be able to work it out yourself if you read over the SB documentation and scrape though the sdp-generated iPhoto header file for the relevant method names. Although - and just to show off a bit - the above script can be run via appscript's ASTranslate tool to convert the Apple events sent by AppleScript into Python/Ruby/ObjC appscript syntax, providing a handy starting point when developing appscript-based code, e.g.:
#import "IPGlue/IPGlue.h" IPApplication *iphoto = [IPApplication applicationWithName: @"iPhoto"]; IPReference *ref = [[[[iphoto albums] byName: @"test"] photos] byName: @"img - 2"]; IPRemoveCommand *cmd = [[ref remove] from: [[iphoto albums] byName: @"test"]]; id result = [cmd send];
HTH
has
[1] In applications such as Address Book and iPhoto that provide 'add' and 'remove' commands as well as 'make' and 'delete', the latter are provided for creating and destroying objects in the master collection (e.g. 'tell app "Foo" to delete element "bar"'). To add/remove items to/from non-master collections without destroying them completely, use the 'add' and 'remove' commands instead, e.g. (e.g. 'tell app "Foo" to remove element "bar" from object "baz"').
-- Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net |