在运行完全空的iTunes库时,如何防止此applescript失败

在运行完全空的iTunes库时,如何防止此applescript失败,applescript,itunes,Applescript,Itunes,您好,当运行在一个完全空的iTunes库上时,我是否可以防止此applescript失败 “iTunes出错:无法获取库播放列表1中每个文件曲目的名称。”库播放列表1中每个文件曲目的名称中的编号-1728 tell application "iTunes" tell every file track of library playlist 1 script performancekludge property tracknames : its na

您好,当运行在一个完全空的iTunes库上时,我是否可以防止此applescript失败

“iTunes出错:无法获取库播放列表1中每个文件曲目的名称。”库播放列表1中每个文件曲目的名称中的编号-1728

tell application "iTunes"
    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
现在固定如下

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

只需检查库是否为空

tell application "iTunes"

    if (count of every file track of library playlist 1) is equal to 0 then
        return
    end if

    tell every file track of library playlist 1

    ...

Thx,这很有效,我只是添加了一个附加项来重置文件(在原始问题中显示了解决方案)