I try to run AppleScript command from Swift code like this:
var appleScriptCmd = "tell application \"System Events\" to make login item at end with properties {path:\"" + appPath + "\", hidden:false, name:\"Some App\"}";
var appleScriptCmd2 = "tell application \"System Events\" to set visible of process \"Safari\" to false";
and then I have tried both:
let script = NSAppleScript(source: appleScriptCmd2)!;
var errorDict : NSDictionary?
script.executeAndReturnError(&errorDict)
if errorDict != nil { print(errorDict!) }
or older approach:
Process.launchedProcess(launchPath: "/usr/bin/osascript", arguments: ["-e", appleScriptCmd])
neither works and simultaneously both commands I have tried are working from Terminal program using osascript -e "some command" tool.
Since your app is sandboxed (Project Settings > Capabilities turn on App Sandbox) you have three options:
~/Library/Application Scripts/
and use NSUserAppleScriptTask.In a sandboxed app
NSAppleScript
refuses to work.