【问题标题】:Why does this applescript that tasks to iTunes sometimes fail with -1712为什么这个对iTunes执行任务的applescript有时会以-1712失败
【发布时间】:2015-01-29 11:54:24
【问题描述】:

我有一些用于在 iTunes 控制下创建文件列表并将其写入文件的 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)

对于一些用户,但我不知道为什么

有人知道为什么,或者我可以如何改进我的脚本

【问题讨论】:

    标签: applescript itunes


    【解决方案1】:

    首先您应该在第一次返回之前close access fileref。否则文本文件可能会保持打开状态。

    如果用户的 iTunes 资料库太大并且脚本运行时间过长,则该错误看起来像是超时。您应该使用 with timeout-block:

    with timeout of 600 seconds
        -- your script here
    end timeout
    

    玩得开心,迈克尔/汉堡

    【讨论】:

    • @SherTerKo 好的,谢谢,我看到了 fileref 问题 - 我会解决的。我认为如果 iTunes 库太大,您可能会对超时有所了解,那么如果我没有设置默认超时,它是大于还是小于 600 秒,即您的更改是减少还是增加默认超时.我的脚本必须处理大型库,所以我可以增加超时时间还是必须以某种方式将脚本处理分成几部分?
    • AFAIK 标准超时时间约为 120 秒。您应该能够将超时设置为您想要的任何值。我记得在超时设置为两个或更多小时的情况下工作的脚本!
    • 2 分钟就是这样!,好吧,你真的可能会在这里做一些事情好)
    猜你喜欢
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多