Applescript / Photoshop - 某种 "wait if busy" 命令?

Applescript / Photoshop - Some sort of "wait if busy" command?

我有一些代码可以不断检查所有打开的文档并在关闭时在 finder 中添加评论。

我有一个问题,如果出现 "Do you wish to save?" 或 "Loading..." 之类的东西,它是 0 和 1 之间的一些奇怪的边缘,似乎无法正确计数。然后它崩溃并显示通用 "General Photoshop Error" 消息。

是否有某种 "Pause/Wait if busy" 命令,或其他解决方法?

repeat

tell application "Adobe Photoshop CS6"

    set D1 to count documents

    local mainDocList
    set mainDocList to {}

    if ((count mainDocList) ≠ D1) then
        log "Main Ran"
        if (D1 > 0) then
            set c to 1
            repeat while (c ≤ D1)
                set mainDocList to mainDocList & (file path of document c)
                set c to c + 1
            end repeat
        end if
    end if

    delay 3

    set D1 to count documents

    local currentDocList
    set currentDocList to {}

    if ((count currentDocList) ≠ D1) then
        log "Current Ran"
        if (D1 > 0) then
            set c to 1
            repeat while (c ≤ D1)
                set currentDocList to currentDocList & (file path of document c)
                set c to c + 1
            end repeat
        end if
    end if


end tell

local closedList, a
set closedList to {}
if ((count mainDocList) ≠ (count currentDocList)) then
    repeat with a in mainDocList
        set a to contents of a
        if {a} is not in currentDocList then set end of closedList to a
    end repeat
end if
log "∆: " & (count closedList)
log "- - - - -"


if ((count closedList) > 0 and ((count mainDocList) > (count currentDocList))) then
    tell application "Finder"
        set c to 1
        repeat while (c ≤ (count closedList))
            tell application "System Events"
                set modDate to modification date of (item c of closedList)
            end tell

            set theDate to current date

            set Y to text -2 thru -1 of ("00" & (year of theDate))
            set M to text -2 thru -1 of ("00" & ((month of theDate) as integer))
            set D to text -2 thru -1 of ("00" & (day of theDate))
            set spartanDate to Y & M & D

            set theTime to (time string of theDate)
            set theTime to text -11 thru -7 of ("00" & (time string of theDate))

            set currentComments to (get comment of (item c of closedList))
            set comment of (item c of closedList) to currentComments & (" | USER-" & spartanDate & "-" & theTime)
            log "******************COMMENTED"
            set c to c + 1
        end repeat
    end tell
end if


end repeat

好吧,如果您在它似乎挂起的代码中指出 WHERE,将会有所帮助。在我看来,任何处理文件的 Applescript 代码都应该大量使用 try...on error...end 块。

try
    ...
 on error errMsg
    display dialog "ERROR: " & errMsg
end try

一旦您确定问题的触发位置并看到错误消息,您和我们就能更好地解决问题。

此外,如果您怀疑弹出的模式对话框是问题的一部分,请用超时块包围该代码:

with timeout of 60000 seconds
   ... could that could otherwise timeout
end

每个脚本语句都会遇到超时,如果您不在 TRY 块中捕获超时或未提前考虑并使用 TIMEOUT 块加以防范,通常会发生不好的事情。