Why repeat a try statement in AppleScript before returning an error?

I’m trying to learn AppleScript and have seen the following example for the Photos app:

    set thisId to id of item 1 of sel
on error errText number errNum
    display dialog "Error: cannot get the image ID" & errNum & return & errText & "Trying again"

        delay 2
        set thisId to id of item 1 of sel
    on error errTexttwo number errNumtwo
        display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
        error "giving up"
    end try --second attempt
end try

Why is there a second try statement doing the same thing after a short delay before giving up? The same is done in several places in this example script.

Is this a normal way of handling errors in AppleScript or is this specific for Photos and if so why?


Applescript is seems to suffer with timing issues that usually are solved be using a delay. Often this delay needs to be tuned to match the speed of a particular model Mac. In other words, the delay hard coded in the the AppleScript may work on a newer faster Mac, but need to be increased when run on a slower Mac.

Source : Link , Question Author : Phiplex , Answer Author : David Anderson

Leave a Comment