Returning a message from Applescript

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Returning a message from Applescript Fri Feb 12, 2010 5:46 pm • by alastor933
In the Help paragraph on running Applescript, in the 'on hazelProcessFile' handler, it says:
-- Though the return value of the script is ignored,
-- it is still logged for debugging purposes
So I thought I could actually get my error message (or anything, really) into Hazel's log, and tried this:
Code: Select all
on hazelProcessFile(theFile)
     return "That went smoothly"
end hazelProcessFile
The log shows that the rule was triggered, but the message is not there.
Did I misunderstand that quote? I'm using 2.3.5.
alastor933
 
Posts: 53
Joined: Wed Mar 05, 2008 3:52 pm
Location: Utrecht, Netherlands

Re: Returning a message from Applescript Sat Feb 13, 2010 9:58 am • by alastor933
Well, it worked with this testcode:
Code: Select all
on hazelProcessFile(theFile)
   error "The script did run." number 603
end hazelProcessFile
I suppose "return value" should be read as "returned error value"?

Then again, no error is returned when the script has an empty error handler:
Code: Select all
on hazelProcessFile(theFile)
   try
      error "The script did run." number 603
   on error the error_message number the error_number
      
   end try
end hazelProcessFile
Adding "return error_message" to the error handler makes no difference.

So I can have the script handle errors, but it must then handle all errors; when one slips through Hazel won't be made aware. Correct?
alastor933
 
Posts: 53
Joined: Wed Mar 05, 2008 3:52 pm
Location: Utrecht, Netherlands

Re: Returning a message from Applescript Tue Feb 16, 2010 4:12 pm • by Mr_Noodle
The comment is out of date. I'll fix that in the next version.

If you look at the top of that page, you'll see that Hazel can process a specific record if you choose to return it otherwise the result is ignored. As for errors, the proper way to throw them is to throw them. You are catching it and not rethrowing it. IIRC, throwing an error is like exceptions in other languages. It short circuits the stack so the notion of a return type is nonexistent.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Returning a message from Applescript Tue Feb 16, 2010 4:29 pm • by alastor933
I don't know any other languages (well, 6502 Assembler - once), but I think I understand what you're saying.
So it's up to my script to deal with any errors it encounters, and inform the user.

I was sort of hoping that Hazel would log the script's doings.
alastor933
 
Posts: 53
Joined: Wed Mar 05, 2008 3:52 pm
Location: Utrecht, Netherlands

Re: Returning a message from Applescript Wed Feb 17, 2010 11:02 am • by Mr_Noodle
You can remove any error handlers and let Hazel receive it but at best it will log it. If you want to bring up a dialog informing the user of the error, that should be done in the script by catching the error and doing it yourself.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Returning a message from Applescript Wed Feb 17, 2010 12:21 pm • by alastor933
That's what I thought.

The Mac is on it's own, no user present, so having Hazel log errors is not an option.

I'll have the script deal with any errors, and let it send some message elsewhere.

Thanks.
alastor933
 
Posts: 53
Joined: Wed Mar 05, 2008 3:52 pm
Location: Utrecht, Netherlands


Return to Support