The execute-applescript
module communicates with the command-line osascript
, but it struggles with handling complex arguments and results.
To parse the output effectively, consider adding the -ss
flag to your osascript
command. This will format the output in AppleScript literals for reliable parsing. The default output format is often unclear.
Alternatively, you can have your AppleScript code convert a list of strings into a JSON string for easier parsing using JSON.parse()
. While AppleScript lacks built-in JSON support, you can utilize Cocoa's NSJSONSerialization
class through the AppleScript-ObjC bridge. Though more effort is required, this approach ensures robustness without introducing additional dependencies.
Another option is to bypass osascript
altogether and call NSAppleScript
from JS via the objc
bridge. Although the objc
bridge may be rough around the edges, it could suffice for your requirements despite the tedious process of unpacking NSAppleEventDescriptor
s.
For those looking to eliminate AppleScript, utilizing nodeautomation
directly from JS allows for application scripting. However, note that while nodeautomation
is effective (used in personal projects), no warranty or free support is provided.
We understand there isn't a perfect solution, especially given the challenges faced by Mac Automation. Despite its shortcomings, the fact that it continues to function is somewhat remarkable.