首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java应用程序不再允许通过Applescript与iTunes对话

Java应用程序不再允许通过Applescript与iTunes对话
EN

Stack Overflow用户
提问于 2013-10-20 20:41:39
回答 2查看 659关注 0票数 0

我已经更改了我的iTunes应用程序,使其以不同的方式与交互,但仍然使用applescript,但是尽管它为我工作,它似乎给我的许多用户带来了问题,一个用户用户已经多次报告了这个错误。

代码语言:javascript
复制
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

代码语言:javascript
复制
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说话的方式,我以前经常用

代码语言:javascript
复制
osascript -a with Runtime.getRuntime().exec()

但现在做了

代码语言:javascript
复制
 ScriptEngineManager mgr = new ScriptEngineManager();
 ScriptEngine engine = mgr.getEngineByName("AppleScript");

这会是问题吗?

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

代码语言:javascript
复制
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每次写入文件(或打开/关闭文件)时都会抱怨--这是为什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-31 09:49:35

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

代码语言:javascript
复制
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 ""
票数 0
EN

Stack Overflow用户

发布于 2015-02-04 14:20:25

看起来你的不同之处是:

代码语言:javascript
复制
> 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

也就是说,“告诉当前的应用程序”去做某事。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19482632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档