此脚本与 iTunes 对话并创建 iTunes 库中所有文件的列表,但如果 iTunes 库很大,可能需要一段时间,我认为部分原因是它正在写入文件,我只是想知道是否这是写入文件的最有效方式
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
close access fileref
end tell
return ""