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

查看:225
本文介绍了通过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 got an error: A privilege violation occurred.

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

我尝试用两种方式(itunesiTunes)大写iTunes,但似乎无济于事.我还尝试在读写权利的基础上添加read权利.最后,我尝试向用户的Music文件夹(存储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文件夹中选择一个特定的文件夹以授予应用程序用户选择的文件访问权限,然后它要求脚本位于单独的文件中,这对于我想要的东西来说太多了2件事情做.对于脚本文件的管理,我不信任用户,并且不需要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.

谢谢

推荐答案

与Apple的开发人员技术支持联系后,我能够解决此问题,实际上实际上是两个问题.

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

首先,权利必须正确区分大小写的束标识符.对于iTu​​nes,权利必须是这样的(请注意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天全站免登陆