我有一些用于在iTunes控件下创建一个fiels列表并将其写入文件的AppleScript,这是完整的脚本:
tell application "iTunes"
if (count of every file track of library playlist 1) is equal to 0 then
set thePath to (POSIX file "/tmp/songkong_itunes_model.txt")
set fileref to open for access (thePath) with write permission
set eof fileref to 0
return
end if
tell every file track of library playlist 1
script performancekludge
property tracknames : its name
property locs : its location
property persistids : its persistent ID
end script
end tell
end tell
set thePath to (POSIX file "/tmp/songkong_itunes_model.txt")
set fileref to open for access (thePath) with write permission
set eof fileref to 0
tell performancekludge
repeat with i from 1 to length of its tracknames
try
set nextline to item i of its tracknames ¬
& "::" & POSIX path of item i of its locs ¬
& "::" & item i of its persistids
write nextline & linefeed as «class utf8» to fileref
end try
end repeat
end tell
close access fileref
有时会给出
create_itunes_model.scpt:428:436: execution error: iTunes got an error: AppleEvent timed out. (-1712)
对于某些用户,但我不知道为什么
有人知道为什么,或者我如何改进我的剧本
答案 0 :(得分:0)
首先你应该在第一次回归之前close access fileref
。否则文本文件可能会保持打开状态。
如果用户的iTunes资料库太大且脚本需要太长时间才能运行,则错误看起来像是超时。你应该使用with timeout-block:
with timeout of 600 seconds
-- your script here
end timeout
玩得开心,迈克尔/汉堡