Passing Custom Text attributes to a AppleScript action

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

Moderator: Mr_Noodle

I would like Hazel to examine the content of a document and figure out if it individually contains certain words. Then for each word it contains build a comma separated list of those (found) words so I can append it to a file name.

So if my list of words is Dog, Cat, Bird, and Ant - then I am looking for something like:
Code: Select all
DOC CONTAINS          APPEND STRING
Bird                   “- Bird”
Dog Cat                “- Dog, Cat”
Dog Cat Ant            “- Dog, Cat, Ant”

I was really hoping the new Custom List functionality would help with this but although it finds multiple words it only returns the first found word to the actions area. (Unless I am doing something wrong.)

So instead I am trying to use a set of custom text attributes:
If any of the following conditions are…
Contents contain match [ • Dog ]
Contents contain match [ • Cat ] etc

…and want to pass them to a Run AppleScript action. But this is where I have hit a problem. I know the the matching is working because I have used a preview file (i.e. Test file has Dog and Bird in its contents) and I can successfully use the Custom Text attributes in other Hazel actions. e.g. Rename will add “Dog” because it was found but not add “Cat” because it wasn’t found.

But if I add a Run AppleScript with an embedded script, eg:

Code: Select all
set theMsg to "Here: "

repeat with anInput in inputAttributes
   set theMsg to theMsg & " • " & (anInput as text)
end repeat

tell application "System Events"
   display dialog theMsg
end tell

I get a dialog that says “Here: • missing value • missing value • missing value • missing value”.

In the Edit Script screen I have used the upper right button to add all four attributes to the import list.

I can’t figure out how to extract the text of the found items (“Dog” and “Bird” in my test file) from inputAttributes.

I am really hoping I am missing something simple. Any ideas?
ngall
 
Posts: 7
Joined: Sun Mar 03, 2019 10:52 pm

Can you post a screenshot of the whole rule?
Mr_Noodle
Site Admin
 
Posts: 11235
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sure. It is a simple test rule to date.

Please ignore the Invoice tag stuff, that just allows me to control when Hazel fires of the rule during this testing.

The Rule:
Image

Condition for “Dog”:
Image

AppleScript Action:
Image
ngall
 
Posts: 7
Joined: Sun Mar 03, 2019 10:52 pm

Hmmm. OK, it looks like this was just a very weird bug.

I kept trying different things and the progressive set of errors eventually stopped making sense.

I deleted the Run AppleScript action, created a new Run AppleScript action (but retyped in the same code) and now everything works. And all of my previously variations also work. :shock:

I have no idea what that means. I am going to submit my log to noodlesoft but this is so odd. Earlier in the process I duplicated the not working rule (all conditions and actions) and the duplicate didn’t work. The duplicate, despite having the same code, still doesn’t work.
ngall
 
Posts: 7
Joined: Sun Mar 03, 2019 10:52 pm

OK, I just went to the duplicate rule. Confirmed it still doesn’t work. Copied the embedded AppleScript code. Deleted the action. Added a new Run AppleScript action. Pasted the code. Added the Inputs.

And, YES, it works now.
ngall
 
Posts: 7
Joined: Sun Mar 03, 2019 10:52 pm

ngall wrote:OK, I just went to the duplicate rule. Confirmed it still doesn’t work. Copied the embedded AppleScript code. Deleted the action. Added a new Run AppleScript action. Pasted the code. Added the Inputs.

And, YES, it works now.


This happens to me pretty frequently, mostly when I go back to an old rule and accidentally add an input attribute to an embedded script in position 2, then delete it, select the last input attribute and add the new input attribute to the end. It's like it messes up the internal index for each input attribute.
ScottDellar
 
Posts: 6
Joined: Tue Apr 21, 2020 2:08 am


Return to Support