以下代码正在尝试打开代理设置对话框,
NSAppleScript *a = [[NSAppleScript alloc] initWithSource:@"tell application \"System Preferences\"\nset current pane to pane \"com.apple.preference.network\"\nactivate\nend tell\ntell application \"System Events\" to tell process \"System Preferences\" to tell window 1\n click button -3\nclick radio button -2 of tab group 1 of sheet 1\nend tell"];
[a executeAndReturnError:nil];
Run Code Online (Sandbox Code Playgroud)
在我将Mac OS升级到10.9之前,它一直运行良好。applescript的第二部分,
tell application \"System Events\" to tell process \"System Preferences\" to tell window 1\n click button -3\nclick radio button -2 of tab group 1 of sheet 1\nend tell
Run Code Online (Sandbox Code Playgroud)
它不再起作用了。因此,如果有人能告诉我原因,我将不胜感激。
编辑:这是我的.entitlements文件信息,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Cocoa 应用程序中从 NSAppleScript 编写 iTunes 脚本,以便将文件添加到库中。
在我的权利文件中,我添加了以下内容:
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.itunes</key>
<array>
<string>com.apple.itunes.library.read-write</string>
</array>
</dict>
Run Code Online (Sandbox Code Playgroud)
然后我这样调用 AppleScript:
var error: NSDictionary? = nil
let appleScript = NSAppleScript(source: "tell application \"iTunes\" to add (POSIX file \"\(path)\") to library playlist 1")
let result = appleScript?.executeAndReturnError(&error)
Run Code Online (Sandbox Code Playgroud)
但它失败并出现错误-10004:iTunes got an error: A privilege violation occurred.
itunes我尝试以两种方式(和)大写 iTunes iTunes,但似乎没有任何效果。我还尝试在读写权利之上添加read权利。最后,我尝试添加对用户音乐文件夹(存储 iTunes 库的位置)的读写访问权限,但这也没有帮助。
为了编写 iTunes 脚本,是否还需要我不知道的其他权利?
我在搜索解决方案时找到了此链接(链接),但它要求用户在其文件夹中选择一个特定文件夹,Library以授予应用程序用户选择的文件访问权限,然后要求脚本位于一个单独的文件中,该文件为 2对于我想做的事情来说太多了。我不信任用户对脚本文件的管理,并且我不需要 1 行 AppleScript 代码的文件。据我了解,另一个缺点NSUserAppleScriptTask是您无法在多个调用中保留脚本的状态,这对我来说不是问题,但对其他人来说可能是问题。
谢谢