代码之家  ›  专栏  ›  技术社区  ›  Pixel

Applescript/Photoshop-某种“忙时等待”命令?

  •  0
  • Pixel  · 技术社区  · 9 年前

    我有一些代码,经常检查任何打开的文档,并在关闭时在finder中添加注释。

    我有一个问题,如果有类似“你想存钱吗?”或者出现“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
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Ron Reuter    9 年前

    好吧,如果您在代码中指明它似乎挂起的位置,将会有所帮助。在我看来,任何处理文件的Applescript代码都应该自由地添加try…on-error…end block。

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

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

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

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

    每个脚本语句都有一个超时,如果没有在TRY块中捕捉到超时,或者没有提前考虑并使用timeout块加以防范,通常会发生不好的情况。

    推荐文章