Re: ScriptingBridge Commands
Re: ScriptingBridge Commands
- Subject: Re: ScriptingBridge Commands
- From: has <email@hidden>
- Date: Wed, 5 May 2010 18:50:53 +0100
John Nairn wrote:
> I have been using ScriptingBridge to script my AppleScriptable Cocoa
> app using Python and Ruby. Today I noticed that commands defined on
> the main application do not work with error message that the
> application has no such attribute. I checked the header file created
> by the ScriptingBridge and see that all commands are defined in a
> generic GEDitCOM_IIItem that is subclass of SBObject:
> [...]
> Is this a bug in the ScriptingBridge framework?
Probably. SB's API is heavily obfuscated and makes all sorts of accidental or deliberate assumptions about how scriptable applications operate that don't actually match up with reality. (e.g. Google "scripting bridge"+"appscript" if you want to see me tearing it various holes.) At any rate, I ran into similar problems:
#!/usr/bin/python
from ScriptingBridge import *
iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
iTunes.activate() # works ok
iTunes.pause() # works ok
iTunes.playOnce_(False) # AttributeError: 'ITunesApplication' object has no attribute 'playOnce_'
Eventually, I figured out the magic invocation via sleuthing and guesswork:
iTunes.play_once_(None, False)
I didn't bother trying to find out if -[iTunesApplication playOnce:] works in ObjC, which is what the sdp-generated header claims it should be. But it wouldn't surprise me if it broke there - sdp's output isn't always correct either.
For comparison, here's how you do it in py-appscript:
#!/usr/bin/python
from appscript import *
itunes = app('iTunes')
itunes.activate()
itunes.pause()
itunes.play()
Much nicer, more capable native API, and far less prone to compatibility problems than SB. (I build heavy-duty workflows with it in my day job.) The only downside is that it's not present in OS X by default, but it's trivial to install via setuptools as long as you've got gcc on your system and it's MIT-licensed so redistribution isn't a problem.
HTH
has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden