【问题标题】:How can I prevent this applescript failing when run against completely empty iTunes library针对完全空的 iTunes 库运行时,如何防止此 AppleScript 失败
【发布时间】:2014-09-18 10:15:47
【问题描述】:

您好,当针对完全空的 iTunes 库运行时,我是否防止此 AppleScript 失败,它失败了

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

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

【问题讨论】:

    标签: applescript itunes


    【解决方案1】:

    只需检查库是否为空...

    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,那行得通,我只是添加以添加文件的重置(在原始问题中显示解决方案)
    猜你喜欢
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    相关资源
    最近更新 更多