I have some applescript for creating a list of the fiels under iTunes control and writing it to a file, this is the complete script:
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
and sometimes it gives
create_itunes_model.scpt:428:436: execution error: iTunes got an error: AppleEvent timed out. (-1712)
for some users, but I dont know why
Does anybody know why, or how I could improve my script
First you should close access fileref
before your first return. Otherwise the text file could stay in an opened state.
The error looks like a timeout if the user's iTunes Library is too big and the script takes too much time to run. You should use a with timeout-block:
with timeout of 600 seconds
-- your script here
end timeout
Have fun, Michael / Hamburg