Timmmm
Timmmm

Reputation: 96547

Is there a library equivalent of Apple Script (osascript)?

Is there a way to do the tasks that Apple Script allows without doing system("osascript ...")? In other words, what does osascript do under the hood?

It links with libDiagnosticMessagesClient, libEdit, AppKit, Carbon, Foundation, ApplicationServices, CoreFoundation and CoreServices so the answer must lie in one of those.

Upvotes: 1

Views: 363

Answers (2)

has
has

Reputation: 167

What vadian says. Calling directly into AppleScript via the AppleScript-ObjC bridge is by far the least awful option available.

AppleEventManager/NSAppleEventDescriptor/NSAppleScript/NSUserAppleScriptTask/OSAKit all lack good high-level APIs and documentation and are a PITA to work with. Scripting Bridge and JavaScript for Automation are broken obfuscated crap; not a fit alternative for anything more than the most trivial tasks. Appscript and its spinoffs are no longer supported. Apple (belatedly) fired its Mac Automation PM and dissolved the team back in 2016, and the whole stack is already starting to bitrot, so it's not really worth investing large amounts of time if you can avoid it.

AppleScript may suck as a language, but it's the only supported option that speaks Apple events right, and the only one that has documentation and community support worth a damn. Which makes a huge difference when you get stuck on how to control individual apps. (Which you will. A lot.)

ASOC takes away 90% of the pain of calling into AS from ObjC or ObjC-bridged languages. Quick how-to for ObjC/Python here; if you're on Swift it may require a bit more boilerplating, but a web search should turn up info on how to do that.

Upvotes: 1

Timmmm
Timmmm

Reputation: 96547

Ah looks like it uses the Apple Event Manager (and OSAscript stands for Open Scripting Architecture).

More info here. Also it looks like there is something to generate an easier API than using the event manager directly - the scripting bridge.

Upvotes: 0

Related Questions