簡體   English   中英

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.

但是我不明白他為什么會出現這個錯誤,我不是,有什么想法嗎?

蘋果腳本

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每次寫入文件(或打開/關閉文件)時都會抱怨-為什么會這樣?

問題原來是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 ""

看起來您的區別是:

> 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

即“告訴當前應用程序”做某事。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM