Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

suppress error dialog in automator

hi,

sometimes my automator app outputs an error dialog "watchmedo encountered an error".
this blocks the app to be restarted automatically (I schedule my apps on a repeated basis), as the app is still open.
how can I suppress error dialogs like this? or can I quit the app once an error is encountered?
those error dialogs (which only go away by clicking OK) kill the possibility to restart the app automatically ...

thanks.

Mac OS X (10.5)

Posted on Sep 7, 2010 9:44 AM

Reply
14 replies

Sep 8, 2010 8:23 AM in response to tasssilo

If you drag one of the events from the *Watch Me Do* action into the workflow window, a *Run AppleScript* action will be added with the script that performs the event. In AppleScript, you can trap errors by using a try statement, for example:
try
-- do something
-- an error will cause execution to jump to the "on error" part
on error errorMessage number errorNumber
-- this is executed if there is an error
-- the error message and number can be used if desired
end try

Jan 10, 2012 4:25 PM in response to tasssilo

Ok. I have a new twist on this problem. I have multipule computers synced with dropbox and iCloud. So I'm trying to tailor all my automation so that the same scripts will work on different computers. So, I write my automators and scripts on my main work maching (a MacBook Pro) and then include everything unique that that machine in try, end try statements. This usually works great, but....


I have created an automator script that first kills all my browsers and a program called CopyPaste (my favorite program ever). It then pauses to make sure eveything has time to close, then trashes all the caches files and my Copypaste clip recorder file. Finally, I have another short pause, then launch copypaste and I'm back where I started. Put the problme is since CopyPaste is currently a little buggy with Lion, I haven't installed it on my mini. When I just use an automator launch module, it gets and error and stops the whole process. I tried writing it something like this.


try

tell application "Copypaste" to activate

end try


but instead of just failing with grace, as it should, it pops up a window wanting to know where the dictionary for CopyPaste is. It isn't anywhere, it's not on this machine, hence the 'try"


Does anyone know how to make automator (or even Applescript) gracefully fail to launch a program?

Jan 10, 2012 5:28 PM in response to Scott Nash

Apple recommends using id's in scripts intended for distribution, to avoid issues such as renamed or missing applications. You can specify an application by its id (com.apple.Safari, for example), which will throw an error instead of asking where it is - the application does need to exist on the machine the script is written on, though.


In the future you should start your own topic rather than trying to hijack an unrelated four month old one.

Jan 10, 2012 8:16 PM in response to tasssilo

Thanks for the suggestions. Unfortunatly, neither worked. Calling to system events still asked for the Copypaste Pro library. Same effect when I created an 'if' statment to determine the existence of the id. But when I did tell Copypaste, even though it should have skipped it, it would not run without calling for the library. When I wrote it with the if statement calling the id then called the id to launch, I just got an error "id not found."


I'm sorry I hyjacked the thread, I try not to waste peoples time asking questions that have already been answered so I searched, and this seem much the same topic (suppressing errors in automator), but still didn't solve the exact problem I'm having.

Jan 10, 2012 9:02 PM in response to Scott Nash

If you do something like (using the appropriate id):


try


tellapplicationid"com.apple.Safari"toactivate

onerrorerrmess


logerrmess

endtry


Then when the script is run on another machine that does not have that application the error should be trapped without it asking where the application is.


Although it deals with something similar, your problem is a bit different than the original poster. Usually, unless you are responding to the original question, you should start a new topic - this helps keep your post from getting buried or skipped over, especially if the topic is already marked as answered.

Jan 11, 2012 5:25 PM in response to tasssilo

I solved it. The trick is ask another valid application (the finder) to launch the one that may not be there. SInce it WILL find the Finder library, this creates no error (well, it creates an error the try function knows how to handle). Here is the script that finally worked:


try

tell application "Finder" to open application file id "com.Peter_Hoerster.CopyPasteUniversal"

end try


Thanks for the help. And, again, didn't mean to mess up the thread by hyjacking it. Sorry if I've caused strife somehow.

Jan 11, 2012 6:22 PM in response to Scott Nash

Hmmm - it is supposed to throw an error when getting the ID. Another way would be to assign the ID to a variable, although you will need to enclose your application terms in a using terms from statement so that the compiler will know what application dictionary to use:


settheIDto"com.apple.missingSafari"-- add/remove "missing" to test

try

using terms fromapplication"Safari"

tellapplicationidtheID-- error if the ID doesn't exist

getURLoftab1ofwindow1-- or whatever

endtell

endusing terms from

onerrorerrmess

beep

logerrmess

endtry

suppress error dialog in automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.