scripting bridge
DESCRIPTION
brief intro to 10.5's new Scripting Bridge framework from PSIG 111TRANSCRIPT
![Page 1: Scripting Bridge](https://reader038.vdocuments.us/reader038/viewer/2022100605/559a9fbf1a28ab02098b46bf/html5/thumbnails/1.jpg)
Red Shed Softwarebetter necessarily means different
Scripting Bridgetell every application to objc_msgSend()
Jonathan ‘Wolf’ Rentzschhttp://rentzsch.com
PSIG 111
![Page 2: Scripting Bridge](https://reader038.vdocuments.us/reader038/viewer/2022100605/559a9fbf1a28ab02098b46bf/html5/thumbnails/2.jpg)
Red Shed Softwarebetter necessarily means different
App Interoperation• examples: “Reveal in Finder”, “Pause iTunes”
• low-level: AppleEvents; high-level: AppleScript
• Standard Cocoa application interop technique:
• Embed an AppleScript, execute via NSAppleScript
• Lame:
• Slow
• AppleScript logic separated from app (ObjC) logic
![Page 3: Scripting Bridge](https://reader038.vdocuments.us/reader038/viewer/2022100605/559a9fbf1a28ab02098b46bf/html5/thumbnails/3.jpg)
Red Shed Softwarebetter necessarily means different
Scripting Bridge• Scripting Dictionary -> Objective-C bridge
• Send AppleEvents by writing ObjC code
• New in 10.5 Leopold
• not to be confused with Bridge Support
• Bridge Support => XML describing all Sys APIs.
for Python+Ruby+F-Script+Nu
• “Faster” than AppleEvents (not really)
![Page 4: Scripting Bridge](https://reader038.vdocuments.us/reader038/viewer/2022100605/559a9fbf1a28ab02098b46bf/html5/thumbnails/4.jpg)
Red Shed Softwarebetter necessarily means different
How It Works• sdef /Applications/iTunes.app
• extracts Scripting dictionary as XML
• sdp -fh --basename iTunes
• generates iTunes.h
• ObjC 2 code: properties galore
• Add ScriptingBridge.framework to project
• Make sure project is targeting 10.5
![Page 5: Scripting Bridge](https://reader038.vdocuments.us/reader038/viewer/2022100605/559a9fbf1a28ab02098b46bf/html5/thumbnails/5.jpg)
Red Shed Softwarebetter necessarily means different
How It Works• #import "iTunes.h"
• [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
• [app playpause];
• Slow on first message send
• parses target scripting dictionary
![Page 6: Scripting Bridge](https://reader038.vdocuments.us/reader038/viewer/2022100605/559a9fbf1a28ab02098b46bf/html5/thumbnails/6.jpg)
Red Shed Softwarebetter necessarily means different
DemoiTunes Playpause