Page 1 of 1

AppleScript compiles in ScriptEditor, Not Hazel

PostPosted: Thu Aug 07, 2008 4:59 pm
by grovberg
Before I spend a lot of time trying to make it work, I just thought I'd run this past the group to see if I just shouldn't bother. I've got an applescript that makes use of an subroutine from Apple to replace text strings. I've used this in conjunction with Hazel for over a year as an external script, and was giddy with delight at the thought of being able to store it within the rule. But when I try to embed the script below, I get

expected "end" but found "on".

at the start of this code. Is this just a bug in Hazel, or something it just doesn't support, or do I need to do something to the code? Any suggestions are appreciated as would REALLY like to take advantage of this excellent new feature.

Code: Select all
on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars

Re: AppleScript compiles in ScriptEditor, Not Hazel

PostPosted: Fri Aug 08, 2008 2:27 pm
by Mr_Noodle
I think the problem is that the embedded script is stuck inside it's own handler (you don't see it but it's there underneath) and you can't define handlers within handlers. So, yes, for now, it's a limitation of Hazel and you are probably better off keeping it external. I've added a bug for it but am not sure how feasible it will be to implement.

Re: AppleScript compiles in ScriptEditor, Not Hazel

PostPosted: Sun Aug 10, 2008 5:48 pm
by njr
This bug seems to occur even without writing in a handler. In my tests, even a trivial script such as "return" exhibits this error. Just entering the script and pressing compile once changes the text area to:
Code: Select all
on hazelProcessFile(theFile)
   return
end hazelProcessFile


...this without actually compiling.

Subsequent attempts to compile throw the handler-in-a-handler error above. It seems that Hazel is wrapping it's own handler text twice. Once invisibly (expected), and once visibly (bug).

It may be relevant that this is on 10.4.11

Re: AppleScript compiles in ScriptEditor, Not Hazel

PostPosted: Mon Aug 11, 2008 7:58 am
by grovberg
Mr_Noodle wrote:I think the problem is that the embedded script is stuck inside it's own handler (you don't see it but it's there underneath) and you can't define handlers within handlers. So, yes, for now, it's a limitation of Hazel and you are probably better off keeping it external. I've added a bug for it but am not sure how feasible it will be to implement.


Oh well, such is life. Thanks for replying and for all the work you put into Hazel.

Re: AppleScript compiles in ScriptEditor, Not Hazel

PostPosted: Mon Aug 11, 2008 11:12 am
by Mr_Noodle
njr: When typing in embedded scripts, you don't stick the handler stuff in there yourself. Just type in the body of the script. You only need to wrap it in a handler when using an external script.

Re: AppleScript compiles in ScriptEditor, Not Hazel

PostPosted: Tue Aug 12, 2008 9:31 pm
by njr
Mr_Noodle wrote:njr: When typing in embedded scripts, you don't stick the handler stuff in there yourself. Just type in the body of the script. You only need to wrap it in a handler when using an external script.


I know, I'm saying the handler stuff appears as soon as I click compile. I didn't type it in.

Re: AppleScript compiles in ScriptEditor, Not Hazel

PostPosted: Wed Aug 13, 2008 12:11 pm
by Mr_Noodle
Ah, sorry. I misread your post.

I'll check this out on a Tiger machine later today but it does not seem to happen on Leopard. Thanks for the report.