我已经更改了我的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每次写入文件(或打开/关闭文件)时都会抱怨--这是为什么?
发布于 2013-10-31 09:49:35
问题原来是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 ""发布于 2015-02-04 14:20:25
看起来你的不同之处是:
> 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也就是说,“告诉当前的应用程序”去做某事。
https://stackoverflow.com/questions/19482632
复制相似问题