1

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. – rubik's sphere Oct 14 '17 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. – Tim Baverstock Dec 8 '17 at 11:52
1

It's ugly but it works...

try
    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. – Tim Baverstock Apr 18 '16 at 15:41

You must log in to answer this question.

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