Swift/AppleScript: Cannot run apple script from Swift code

后端 未结 1 1886
眼角桃花
眼角桃花 2021-01-15 17:08

I try to run AppleScript command from Swift code like this:

 var appleScriptCmd = \"tell application \\\"System Events\\\" to make login item at end with pr         


        
相关标签:
1条回答
  • 2021-01-15 17:44

    Since your app is sandboxed (Project Settings > Capabilities turn on App Sandbox) you have three options:

    • Add temporary entitlements for the applications you want to use.
    • Put your scripts in the appropriate directory in ~/Library/Application Scripts/ and use NSUserAppleScriptTask.
    • Implement an AppleScriptObjC bridge and run the AppleScript code from the ASOC framework (requires also an Objective-C bridging header file).

    In a sandboxed app NSAppleScript refuses to work.

    0 讨论(0)
提交回复
热议问题