I'm writing some fairly complex Applescripts, but when something goes wrong - Apple event timed out - or similar, I can't tell precisely where it failed.

At the moment, I'm wrapping all handlers with try blocks, with an on error that re-raises the error, with a reference to the handler name and the value of a variable that I set at various points through the handler so I can isolate the error to somewhere between two points.

** Is there a way to get Applescript to say 'Apple event timed out at line 15 in await(), at line 60 in connectRemoteUser(), at line 90 in autostartTestUsers()' without having to code it all directly?

I can't rely on the script editor's location highlighting because the errors happen intermittently when the script is out in production.

  • Did you ever find a solution for this? I share your frustration. Oct 14, 2017 at 2:23
  • @rubik'ssphere Sadly, no. Happily, we've moved away from AppleScript (which I was using to start multiple desktops on the same machine, to run multiple simulators) because Facebook's fbsimctl made things much easier. If I never have to write another Applescript abomination, I'll be a happy bunny. Dec 8, 2017 at 11:52

1 Answer 1


It's ugly but it works...

    set marker to 1
    -- do stuff
    set marker to 2
    -- do stuff
    set marker to 3
    1 / 0
    set marker to 4
on error errMsg number errNum
    tell application "SystemUIServer"
        display alert (marker & space & errMsg & return & return & "Error number " & errNum as text) buttons "Cancel" cancel button "Cancel"
    end tell
end try
  • 2
    That's pretty much what I said I didn't want to be doing in the question: I'm already catching and re-raising errors for all handlers, and only displaying the dialogue for the topmost. Apr 18, 2016 at 15:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .