简体   繁体   English

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

[英]Java application no longer allowed to talk to iTunes via Applescript

I've changed my Java application to interact with iTunes in a different way but still using applescript, but although it is working for me it seems to be causing problems for alot of my users, one user user has reported this error appearing numerous times 我已更改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.

but I don't understand why he would be getting this error and I am not, any ideas ? 但是我不明白他为什么会出现这个错误,我不是,有什么想法吗?

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

Update I also just realized that I have changed the way I talk to iTunes, I used to use 更新我也刚刚意识到,我曾经改变过与iTunes交谈的方式

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

but now do 但是现在

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

could that be the issue ? 这可能是问题吗?

Update 2 This is a pure Applescript problem because a similar error occurs when i run from Applescript editor 更新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.

The problem is not after all not having access to iTunes, rather iTunes complains every time it writes to the file (or open/closes the file) - why would that be ? 问题不是毕竟不能访问iTunes,而是iTunes每次写入文件(或打开/关闭文件)时都会抱怨-为什么会这样?

The issue turned out to be the Applescript itself, it had nothing to do with Java or how I was calling Applescript, the error was an error about iTunes not being able to write to files on the filesystem, modifying as follows fixed the problem 问题原来是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 ""

Looks like your difference was: 看起来您的区别是:

> 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

ie the 'tell current application' to do something. 即“告诉当前应用程序”做某事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM