AppleScript compiles in ScriptEditor, Not Hazel

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

Moderator: Mr_Noodle

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
grovberg
 
Posts: 17
Joined: Thu Nov 30, 2006 3:44 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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
njr
 
Posts: 4
Joined: Mon Nov 27, 2006 7:48 pm

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.
grovberg
 
Posts: 17
Joined: Thu Nov 30, 2006 3:44 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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.
njr
 
Posts: 4
Joined: Mon Nov 27, 2006 7:48 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron