Friday, January 20, 2017
  • Index
  •  » Automator
  •  » Cancelling an AS display dialog generates an Automator error in 10.11

#1 2015-11-09 06:29:05 am

flex20
Member
From: Sydney, Australia
Registered: 2010-08-24
Posts: 202

Cancelling an AS display dialog generates an Automator error in 10.11

Hi,
I have several Automator applets with Run AppleScript actions.
Many of them started generating an error after upgrading to El Capitan 10.11 and 10.11.1.
The error massage is: "The action “Run AppleScript” encountered an error"
I've been able to narrow down the error to cancelling an AS display dialog box.
This is a test AS script:

Applescript:

tell application "Finder"
   activate
   display dialog "test run AS in Automator" buttons {"Cancel", "OK"}
   display dialog "test 2nd display dialog" buttons {"Cancel", "OK"}
end tell

And this is the corresponding automator workflow:

Applescript:

on run {input, parameters}
   
   tell application "Finder"
       activate
       display dialog "test run AS in Automator" buttons {"Cancel", "OK"}
       display dialog "test 2nd display dialog" buttons {"Cancel", "OK"}
   end tell
   
   return input
end run

The workflow must be saved and run as an applet to generate the error when cancelling the dialog.
The second dialog is addd to show that the script continues on "OK" as expected.

Please, can somebody explain why cancelling an AS dialog generates an error in an Automator applet now?
Is this an Automator bug in 10.11? Is there a workaround?


Filed under: , error cancel dialog

Offline

 

#2 2015-11-12 05:27:43 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 4160

Re: Cancelling an AS display dialog generates an Automator error in 10.11

Hi.

This looks like a bug. Except in the case of 'choose from list', it's normal behaviour for a "Cancel" button to generate error number -128 ("User canceled."). However, this should simply stop the execution of the script and not set off any alarms.

I notice on my El Capitan machine that cancelling a dialog in a script run in Script Editor now returns a result in Script Editor's Result pane: error "User canceled." number -128. On earlier systems, the pane would remain blank.

This doesn't appear to be cause any problems with scripts saved directly as applets, but it seems that Automator actions are reporting the error.

If the dialog command's in the script's 'run' handler, a possible work-round would be to enclose it in a 'try' block, which would trap the error and cause it to be ignored. Of course then you'd have to include everything after that point in the block too to stop it being executed. Not very satisfactory, but it's something:

Applescript:

on run {input, parameters}
   
   try
       display dialog "test run AS in Automator" buttons {"Cancel", "OK"}
       display dialog "test 2nd display dialog" buttons {"Cancel", "OK"}
       
       -- Rest of code.
       
   end try
   
   return input
end run


NG

Offline

 

#3 2015-11-12 05:48:39 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4887

Re: Cancelling an AS display dialog generates an Automator error in 10.11

Perhaps you could take Nigel's suggestion a bit further, and wrap it like this:

Applescript:

on run {input, parameters}

try
display dialog "test run AS in Automator" buttons {"Cancel", "OK"}
display dialog "test 2nd display dialog" buttons {"Cancel", "OK"}

-- Rest of code.

return input

on error number -128
return missing value
end try

end run


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#4 2015-11-14 10:42:46 am

flex20
Member
From: Sydney, Australia
Registered: 2010-08-24
Posts: 202

Re: Cancelling an AS display dialog generates an Automator error in 10.11

Nigel Garvey wrote:

This looks like a bug ...

Shane Stanley wrote:

Perhaps you could take Nigel's suggestion a bit further, and wrap it like ...

Hi Nigel and Shane,
Sorry for replying so late but I had a stint in the hospital for something minor which kept me bedridden for a few days.

Thank you for your help and suggestions.
Kind of hating temporary fixes which are then forgotten and left there long after the bug has been fixed and staying with medical speak, I decided on major AS surgery:
Being already in the process of updating most of my working scripts which can benefit from the recent AS capabilities such as script libraries, ASObjC, use command, etc. I decided to also drop using the Automator all together and use direct AS applets instead.

Shane, many thanks for the BridgePlus library and the reference to Takaaki Nagoya's manual.
It is amazing how powerful but clean (bye-bye most tell blocks), readable and to-the-point scripts can be now.

Cheers,
Chris

Offline

 
  • Index
  •  » Automator
  •  » Cancelling an AS display dialog generates an Automator error in 10.11

Board footer

Powered by FluxBB

[ Generated in 0.040 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)