The MacRuby install includes macirb, the MacRuby equivalent of Ruby's irb command line interpreter.
Here is an example script to read from and control iTunes via the scripting bridge.
framework 'ScriptingBridge
itunes = SBApplication.applicationWithBundleIdentifier('com.apple.iTunes')
itunes.playpause
track = itunes.currentTrack
name = track.name
Here is an example script for Photoshop.
photoshop = SBApplication.applicationWithBundleIdentifier('com.adobe.photoshop')
doc = photoshop.currentDocument
n = doc.name
doc.rotateCanvasAngle 45
To see a list of what methods are available for an object, call its methods method as follows, subtracting out the methods available to Object.
photoshop.methods(true,true) - Object.methods(true,true)
Pretty cool stuff. I was never a big fan of AppleScript, and in fact stayed away from scripting applications because I didn't like using AppleScript. I can see MacRuby busting the doors off of scripting on the Mac!
No comments:
Post a Comment