• 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: Can't Remove Photos from iPhoto Slideshow using AppleScript / Scripting Bridge
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't Remove Photos from iPhoto Slideshow using AppleScript / Scripting Bridge


  • Subject: Re: Can't Remove Photos from iPhoto Slideshow using AppleScript / Scripting Bridge
  • From: has <email@hidden>
  • Date: Sat, 22 Nov 2008 10:27:25 +0000

 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

_______________________________________________
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
  • Prev by Date: Getting list of items from network slow
  • Next by Date: Re: A puzzle
  • Previous by thread: Can't Remove Photos from iPhoto Slideshow using AppleScript / Scripting Bridge
  • Next by thread: Re: Can't Remove Photos from iPhoto Slideshow using AppleScript / Scripting Bridge
  • Index(es):
    • Date
    • Thread