通过 NSAppleScript 编写 iTunes 脚本的沙盒权限 [英] Sandbox entitlement to script iTunes via NSAppleScript

查看:41
本文介绍了通过 NSAppleScript 编写 iTunes 脚本的沙盒权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的 Cocoa 应用程序中的 NSAppleScript 编写 iTunes 脚本,以便将文件添加到库中.

I'm trying to script iTunes from NSAppleScript in my Cocoa app in order to add a file to the library.

在我的权利文件中,我添加了以下内容:

In my entitlements file, I added the following:

<key>com.apple.security.scripting-targets</key>
    <dict>
        <key>com.apple.itunes</key>
        <array>
            <string>com.apple.itunes.library.read-write</string>
        </array>
    </dict>

然后我像这样调用 AppleScript:

I then call the AppleScript like this:

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)

但它失败并显示错误 -10004:iTunes 出现错误:发生权限冲突.

but it fails with an error -10004: iTunes got an error: A privilege violation occurred.

我尝试将 iTunes 以两种方式(itunesiTunes)大写,但似乎没有任何效果.我还尝试在读写权限之上添加 read 权限.最后,我尝试添加对用户音乐文件夹(存储 iTunes 库的位置)的读写访问权限,但这也无济于事.

I tried capitalizing iTunes both ways (itunes and iTunes) but nothing seems to work. I also tried adding, on top of the read-write entitlement, the read entitlement. Finally, I tried adding read and write access to the user's Music folder (where the iTunes library is stored) and this didn't help either.

是否还有其他我不知道的必需权利才能编写 iTunes 脚本?

Is there another required entitlement that I'm not aware of in order to script iTunes?

我在寻找解决方案时找到了此链接(链接) 但它要求用户在他的 Library 文件夹中选择一个特定的文件夹来为应用程序用户选择的文件提供访问权限,然后它要求脚本位于一个单独的文件中,这有两件事太多了为了我想做的事.我不信任用户关于脚本文件的管理,我不需要 1 行 AppleScript 代码的文件.另一个缺点,据我所知 NSUserAppleScriptTask 是你不能在多次调用中保持脚本的状态,这对我来说不是问题,但可能对其他人有问题.

I found this link in my search for a solution (link) but it requires the user to select a specific folder in his Library folder to give the application user-selected file access and then it requires the script to be in a separate file which is 2 things too many for what I want to do. I don't trust the user regarding the management of the script files and I don't need a file for 1 line of AppleScript code. Another disadvantage, as I understand NSUserAppleScriptTask is that you can't persist a script's state across multiple calls, which is not a problem in my case but could be for someone else.

谢谢

推荐答案

联系了苹果的开发者技术支持后,我解决了这个问题,实际上是二合一的问题.

After contacting the Developer Technical Support of Apple, I was able to solve this problem, which is actually 2 problems in one.

首先,权利需要正确区分捆绑标识符.对于 iTunes,权利必须是这样的(注意 iTunes 中的大写 T):

First, the entitlements need to have the bundle identifiers properly cased. For iTunes, the entitlements must be like this (note the capital T in 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>

然后,除非 AppleScript 代码像这样在末尾包含 of source 1,否则会发生特权冲突:

Then, the privilege violation will occur unless the AppleScript code includes of source 1 at the end like this :

tell application "iTunes" to add (POSIX file "your/path/to/mp3.mp3") to library playlist 1 of source 1

你去吧!

这篇关于通过 NSAppleScript 编写 iTunes 脚本的沙盒权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆