Java应用程序不再允许通过Applescript与iTunes通信(Java application no longer allowed to talk to iTunes via Applescr

系统教程 行业动态 更新时间:2024-06-14 16:59:47
Java应用程序不再允许通过Applescript与iTunes通信(Java application no longer allowed to talk to iTunes via Applescript)

我已经改变了我的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每次写入文件时都会抱怨(或打开/关闭文件) - 为什么会这样?

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

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

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

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 ?

最满意答案

问题原来是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 ""

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

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

更多推荐

本文发布于:2023-04-17 08:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/b673282f8470e8f1a14887fb37dfe58e.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   通信   iTunes   Applescript   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!