AppleScript Called by Hazel quit working

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

Moderator: Mr_Noodle

I've been using a AppleScript called by Hazel for several years. Purpose is to decipher pdf statements and bills and "intelligently" create a file name.

Recently - within the last 2 weeks, that script has ceased to work correctly. I'm sorry that I cannot articulate known system software changes. I'm running Big Sur 11.2.1 on a 2015 iMac, but I don't recall when that software update occurred and I haven't tracked Hazel updates. I do try to keep all software current.

The script executes as it is supposed to in standalone test.

However when called by Hazel no filename is (apparently) generated by the script (I do not know that certainly) and the 3 actions that follow the Run AppleScript action do not appear to execute.

I know that Hazel calls the script - I can see the beginning of the script opening the pdf using PDFPen. But then it ends instead of generating a filename. The Hazel log shows the rule matched, followed by "Done processing folder Action".

My fundamental question is: can you help me find a way to test this? I can single-cycle thru the code (Script Debugger) in stand alone, but that doesn't work when invoked by Hazel. I need to be able to learn where the code fails when called by Hazel.

Sorry, but I don't understand how to attach a screenshot to show you the rules.
Karl.Browning
 
Posts: 16
Joined: Sun Dec 09, 2012 10:18 am

Re: AppleScript Called by Hazel quit working Tue Mar 02, 2021 11:51 am • by Mr_Noodle
I suggest adding logging/displaying of values at different points in the script to isolate where the problem lies. You can also try turning on debug mode (https://www.noodlesoft.com/kb/hazel-debug-mode/) though if the logs do not indicate an error running the script then that may not show much more.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

As always, thank you for the pointers.

Here is what I have learned:
The "problem" seems to be related to returning values from the script. The script returns a filename and a comment. The actions include renaming the file with the returned filename and adding the comment.

This is the script return line: return {hazelOutputAttributes:{kbbFileName:fileName, kbbComment:theFileComment}}
The script options, in the right panel (custom attributes script exports) has the two names as returned by the script.

I observed that the tokens in the rename pattern were unusual (to me). They contained: hazelcustomtoken:kbbFileName

I do not know how that gets set but when I am able to remove the "hazelcustomtoken" part the rule works. when those words are there the rule doesn't work (the script does pass the name and comment back).

Can you teach me what I am doing wrong or not doing that causes the token name to be changed, please?

Thanx.
Karl
Karl.Browning
 
Posts: 16
Joined: Sun Dec 09, 2012 10:18 am

Is it all PDFs / statements? Or just a particular one? I'm thinking maybe the format of the PDF has changed.
MartinPacker
 
Posts: 1
Joined: Fri Sep 11, 2015 1:05 pm

Thank you for the reply.
All pdfs are created equally - ie, the script is returning the correct values, the rename is failing, I think because the tokens are not the same name as the ones specified in the options panel.
Karl.Browning
 
Posts: 16
Joined: Sun Dec 09, 2012 10:18 am

Re: AppleScript Called by Hazel quit working Mon Apr 05, 2021 11:06 am • by Mr_Noodle
Not sure how the tokens got corrupted. If it happens again, see if you can replicate the steps and send them over.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Not sure how the tokens got corrupted. If it happens again, see if you can replicate the steps and send them over.


Thank you. It took a bit of time before I made the kind of change that causes the corruption of the token. I suspected it earlier, but have now confirmed it. When I change the script to be called (I do so whenever I create a new version of the script) and save the rule the tokens are changed to "hazelcustomtoken:mytokenname.

The "different" behavior from the earlier versions is that previously one didn't have to re-enter the tokens in the "Options" "i" button.

Since I maintain this script with some regularity I'm pretty sure (although I wouldn't bet a lot of money) that updating the Options is a requirement in the new version of Hazel that wasn't in (or perhaps wasn't enforced in) the previous versions of Hazel.

Regardless, I accept this as a responsibility that I need to remember to do each time I update the version of the called script.

Thanks again for all the good you do.
Karl
Karl.Browning
 
Posts: 16
Joined: Sun Dec 09, 2012 10:18 am

How are you changing the script? Can you record a video of this and email it in?
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:How are you changing the script? Can you record a video of this and email it in?


Probably I have not represented correctly the sequence of events, so I'll try here:

Changing a script does not affect the operation of Hazel. As long as I continue to use the same filename for the script Hazel keeps on running that script. In and of itself this does not cause the tokens to be changed or "corrupted".

When I make a significant revision to the script I give it a different version number and that is represented in the filename of the script. For example, the current script is v5.1. If/when I change that name to v5.2. I change the Run AppleScript task line to reflect the change in script name.

At this point it is necessary to also update the Options button with the token names. This is different behavior than Hazel 4 in that V4 remembered the tokens and "assumed" that they would be the same with a new script name. This is also the step that I did not take previously that caused me to think Hazel wasn't working properly. While it might be nice for Hazel to remember the tokens from change to change - I think I understand why that may not be a viable option.

As always, I appreciate your interest and thoughts.

Best.
Karl
Karl.Browning
 
Posts: 16
Joined: Sun Dec 09, 2012 10:18 am

Thanks for the clarification. I'm not sure if anything with this has changed from v4 to v5. I'll look into it though I'd consider it a lower priority issue at the moment.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support