com.apple.iTunes AEDeterminePermissionToAutomateTarget 始终是 return -600

com.apple.iTunes AEDeterminePermissionToAutomateTarget is always return -600

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
    }
}

info.plist:

<key>NSAppleEventsUsageDescription</key>
<string>somedescriprtion</string>

iTunes 运行 但我总是得到 -600 osstatus。 我该如何解决? iTunes 捆绑 ID 没问题。

/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' /Applications/iTunes.app/Contents/Info.plist
com.apple.iTunes

P.S 但如果我使用 "com.apple.dt.Xcode" 捆绑 ID,它就可以工作!

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

NSAppleEventsUsageDescription 键的良好调用 — 如果您 link 针对 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,包括指定 两项 权利的方法,但根据当前 OS 版本,只有一项适用。