2016-05-07 6 views
0

Ich habe Code, der ständig nach offenen Dokumenten sucht und einen Kommentar im Finder hinzufügt, wenn er geschlossen wird.Applescript/Photoshop - Eine Art von "Warten, wenn beschäftigt" Befehl?

Ich habe ein Problem, dass, wenn etwas wie die "Möchten Sie speichern?" oder "Loading ..." erscheint, es ist ein merkwürdiger Limbo zwischen 0 und 1 und scheint nicht richtig zu zählen. Es stürzt dann mit der generischen "General Photoshop Error" Nachricht ab.

Gibt es einen Befehl "Pause/Wait If Busy" oder etwas anderes?

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 

Antwort

0

Nun, es würde helfen, wenn Sie WHERE in dem Code angegeben scheint es zu hängen. Meiner Meinung nach sollte jeder Applescript-Code, der mit Dateien zu tun hat, großzügig mit try ... on error ... end blocks gesprenkelt werden.

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

Sobald Sie identifiziert haben, wo das Problem ausgelöst wird, und die Fehlermeldung, Sie und wir würden besser in der Lage, das Problem zu beheben.

Auch wenn Sie, dass ein modaler Dialog vermuten Aufspringen Teil des Problems ist, umkreisen diesen Code mit einem Timeout-Block:

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

Jede Skriptanweisung unterliegt einem Timeout, und schlechte Dinge in der Regel passieren wenn Sie das Timeout in einem TRY-Block nicht abfangen oder vorausdenken und sich mit einem TIMEOUT-Block dagegen wehren.

+0

Ich fühle mich jetzt dumm. Aus irgendeinem Grund kam mir das Hinzufügen von "try/error" -Blöcken nicht einmal in den Sinn. Ich fügte eine Fehlerverzögerung um jeden Zählblock hinzu und das brachte alles in Ordnung. Vielen Dank! – Pixel

+0

Gern geschehen, Pixel! Keine Notwendigkeit, sich dumm zu fühlen, wir brauchen alle von Zeit zu Zeit Hilfe. –

Verwandte Themen