com.apple.iTunes AEDeterminePermissionToAutomateTarget始终返回-600

Hor*_*oko 7 macos swift macos-mojave

import ScriptingBridge

class iTunesAccess {
    static func requestAccess() -> Bool {
        guard #available(OSX 10.14, *) else {
            return true
        }
        if var addressDesc = NSAppleEventDescriptor(bundleIdentifier: "com.apple.iTunes").aeDesc?.pointee {
            let appleScriptPermission = AEDeterminePermissionToAutomateTarget(&addressDesc, typeWildCard, typeWildCard, true)
            AEDisposeDesc(&addressDesc)
            return appleScriptPermission == noErr
        }
        return false
    }
}
Run Code Online (Sandbox Code Playgroud)

info.plist中:

<key>NSAppleEventsUsageDescription</key>
<string>somedescriprtion</string>
Run Code Online (Sandbox Code Playgroud)

iTunes运行但我总是得到-600 osstatus.我怎么解决它?iTunes捆绑包ID很好.

/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' /Applications/iTunes.app/Contents/Info.plist
com.apple.iTunes
Run Code Online (Sandbox Code Playgroud)

PS,但如果我使用"com.apple.dt.Xcode"捆绑ID它的工作原理!

PPS我找到了repo https://github.com/melchor629/iTunes-Scrobbler并构建它.它也有效.

Chr*_*s N 5

很好地调用NSAppleEventsUsageDescription密钥——如果你链接到 10.14 SDK,这是必需的——但是如果你的应用程序是沙盒的,你还需要一个适当的 Apple 事件权利:com.apple.security.scripting-targets如果可以,或者com.apple.security.temporary-exception.apple-events如果你必须。有关更多详细信息,请参阅https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/AppSandboxTemporaryExceptionEntitlements.html以获取更多详细信息,包括一种指定两种权利的方法,但根据当前操作系统版本,只有一种适用.