【问题标题】:Java application no longer allowed to talk to iTunes via ApplescriptJava 应用程序不再允许通过 Applescript 与 iTunes 通信
【发布时间】:2013-10-29 05:50:31
【问题描述】:

我已更改我的 Java 应用程序以以不同的方式与 iTunes 交互,但仍使用 applescript,但尽管它对我有用,但似乎给我的很多用户带来了问题,一位用户用户报告出现此错误无数次

10/20/13 12:37:44.553 PM iTunes[74256]: AppleEvents/sandbox: Returning 
errAEPrivilegeError/-10004 and denying dispatch of event rdwr/writ from process 
'Jaikoz'/0x0-0x413413, pid=19717, because it is not entitled to send an AppleEvent 
to this process.

但我不明白为什么他会收到这个错误而我没有,有什么想法吗?

Applescript

tell application "iTunes"
    set thePath to (POSIX file "/tmp/jaikoz_itunes_model.txt")
    set fileref to open for access (thePath) with write permission
    set eof fileref to 0
    set mainLibrary to library playlist 1
    repeat with nexttrack in (get every track of mainLibrary)
        if (class of nexttrack is file track) then
            try
                set trackname to name of nexttrack
                set loc to location of nexttrack
                set locpath to POSIX path of loc
                set persistid to persistent ID of nexttrack
                set nextline to trackname & "::" & locpath & "::" & persistid
                write nextline & "\n" as "utf8" to fileref  starting at eof
            end try
        end if
    end repeat
end tell
return ""

更新 我也刚刚意识到我已经改变了与 iTunes 交谈的方式,我曾经使用过

osascript -a with Runtime.getRuntime().exec()

现在做

 ScriptEngineManager mgr = new ScriptEngineManager();
 ScriptEngine engine = mgr.getEngineByName("AppleScript");

这可能是问题吗?

更新 2 这是一个纯粹的 Applescript 问题,因为当我从 Applescript 编辑器运行时会发生类似的错误

25/10/2013 10:39:39.816 iTunes[3366]: AppleEvents/sandbox: Returning 
errAEPrivilegeError /-10004 and denying dispatch of event rdwr/writ
from process 'AppleScript Editor'/0x0-0x24d24d, pid=12717, because
it is not entitled to send an AppleEvent to this process.

问题毕竟不是无法访问 iTunes,而是 iTunes 每次写入文件(或打开/关闭文件)时都会抱怨 - 为什么会这样?

【问题讨论】:

  • 非常不清楚的问题!我们可以看到一些代码吗?您的项目在某处可用吗?
  • 看起来您的应用已被沙盒化。您是否启用了将 Apple 事件发送到 iTunes 的正确权利?
  • @NicholasRiley 嗨,不,我可能不明白,但我不明白为什么我的应用程序会被沙盒化,或者如何获得这些权利。我自己的电脑没有这个问题,可以用请详细说明
  • 实际上取决于您构建 Java 应用程序的方式。我对 Java Mac 应用程序打包的最新技术不是很熟悉——我上一次使用它是在 10 多年前,抱歉。假设您使用的是 Apple Java 6,您可以尝试在 Apple 的 java-dev 列表上发布,或者使用 Java 7 的相应 OpenJDK 列表。
  • @NicholasRiley 以前的版本和这个版本的包装明智(id do sisagn with a devloperid)之间没有任何变化,但是我使用的苹果脚本但applescript已经改变,我已经将它添加到问题中

标签: java macos applescript itunes


【解决方案1】:

问题原来是Applescript本身,它与Java或我如何调用Applescript无关,错误是iTunes无法写入文件系统上的文件的错误,修改如下修复了问题

set thePath to (POSIX file "/tmp/jaikoz_itunes_model.txt")
set fileref to open for access (thePath) with write permission
set eof fileref to 0
tell application "iTunes"
    set mainLibrary to library playlist 1
    repeat with nexttrack in (get every track of mainLibrary)
        if (class of nexttrack is file track) then
            try
                set trackname to name of nexttrack
                set loc to location of nexttrack
                set locpath to POSIX path of loc
                set persistid to persistent ID of nexttrack
                set nextline to trackname & "::" & locpath & "::" & persistid
                tell current application to write nextline & "\n" as «class utf8» to fileref
            end try
        end if
    end repeat
end tell
close access fileref
return ""

【讨论】:

    【解决方案2】:

    看起来你的区别是:

    > set thePath to (POSIX file "/tmp/jaikoz_itunes_model.txt")
    > set fileref to open for access (thePath) with write permission
    > set eof fileref to 0
    2,4d4
    <     set thePath to (POSIX file "/tmp/jaikoz_itunes_model.txt")
    <     set fileref to open for access (thePath) with write permission
    <     set eof fileref to 0
    14c14
    <                 write nextline & "\n" as "utf8" to fileref  starting at eof
    ---
    >                 tell current application to write nextline & "\n" as «class utf8» to fileref
    18a19
    > close access file ref
    

    即“告诉当前应用程序”做某事。

    【讨论】:

    • 我会将此作为评论发布到您的条目中,除非我需要编写一个代码块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 2016-08-30
    • 2017-06-06
    相关资源
    最近更新 更多