So I wrote a small service that, when hotkey is pressed, captures a screenshot, uploads it to imgur and copies the link to the buffer. Thing is, if for some reason I decide NOT to capture anything and press Esc (or any other key), it breaks and displays an error. I want the service not to display an error when I manually cancel the procedure. How do I achieve that?

Edit: I have tried wrapping my script in try and adding on error errMsg before closing with end try. It worked but I wonder if there's a more idiomatic solution.

  • No, using try statements and error handlers are how AppleScript deals with it. – user3439894 Aug 3 '16 at 12:56
  • @user3439894 is there a way to connect an event (i.e. displaying a notification) to the script depending on whether there was an error or not? For example, if there was an error display "error" and play 'bad' sound, if there wasn't any display "finished" and play 'good' sound. – Arthmost Aug 3 '16 at 13:34
  • Are you referring to posting a notification using the Notification Center? If yes, see display notification and for playing a sound I've used, e.g., do shell script "afplay /System/Library/Sounds/Purr.aiff", in the past. – user3439894 Aug 3 '16 at 13:58

Had to wrap my script with try and end try to suppress errors.

You must log in to answer this question.

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