0

A certain API I want to use only works with AppleScript to request information from an App. I want to build a MacOSX application, can I use apple script in this application? Are there work arounds to implement apple script?

Thanks!

0

2 Answers 2

2

If you want to talk to another app only via AppleScript, this might be as easy as using a couple API's in the NSAppleScript class.

E.G.

initWithSource: (I'm assuming Objective-C but of course there are Swift equivalents) and executeAndReturnError:

Sign up to request clarification or add additional context in comments.

Comments

0

Don't bother with NSAppleScript: it's a right PITA for passing data in and out as you have to pack and unpack every NSAppleEventDescriptor yourself. The simplest way to call AS inside a Cocoa app is via the AppleScript-ObjC bridge - that lets your ObjC code call AS handlers like native methods (and vice-versa), and performs the AS-ObjC value conversions for you.

Other options for sending Apple events directly from ObjC/Swift:

  • macOS's ScriptingBridge framework, which is crippled, crappy and horribly obfuscated, but may suffice trivial tasks (AS via ASOC is still the safest and most robust choice though)

  • the SwiftAutomation framework that I'm developing with the goal of pitching it to Apple in the new year. It's a new codebase and I'm still knocking out bugs, but the design descends from appscript which has proven itself a true alternative to AppleScript over a decade of real-world use.

BTW, if SwiftAutomation is of interest to you, please a file feature request on bugreport.apple.com asking Apple to adopt it and include in 10.13. The more duplicate tickets they get, the more likely they are to pay attention.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.