Trigger using "Subject or Contents" contains"X or Y or Z"

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

Moderator: Mr_Noodle

Good evening. I'm new to my Mac and new to Hazel, so please pardon me if this is old for everyone. I'm trying to get some of my first rules set up.

Is there an easy way with Hazel to take an action if "Subject or Contents" contains a set value? Or, if one wants to do this, does one have to set up separate triggers first for "if subject" and then "if contents?"

That's question #1.

Question #2 : I want to watch a directory for notes where either the Subject or the Contents contain either the (example) words Tomato, Lettuce, or Mushroom. Is there a way to do the "Tomato or Lettuce or Mushroom" all in one criteria instead of as separate entries?

Thanks!!! Enjoying Hazel so far, but I have a lot to learn.

Cheers,

Mark
markewallace
 
Posts: 6
Joined: Sun Feb 17, 2013 10:49 pm

What kinds of files are we talking about here? Not all files will include this type of information in a way that Hazel can understand.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Oh, good question. For now, just text files. It would be interesting to know for future reference if there are other file types that this would work with, but for the moment I'm just interested in this for text files.

Thanks,

Mark
markewallace
 
Posts: 6
Joined: Sun Feb 17, 2013 10:49 pm

Text files don't have a built-in notion of subject. You can have Hazel do a match based on words in the content in general though by doing "Contents contains". And you will have to do separate conditions for each word; just make sure to set it to match "any" of the conditions and not "all".
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Oh, well, duh. I guess that's true (i.e. text files not having subjects). Okay, so fair enough. I can search by content easily enough.

Is there a way to submit a feature request? Having to do separate rules for several keywords, although doable, is a pain. It would be muuuuch easier to just be able to say X or Y or Z.

Thanks again,

Mark
markewallace
 
Posts: 6
Joined: Sun Feb 17, 2013 10:49 pm

What Mr_Noodle is saying is that "subject" is not a metadata field in any text file. In other words, just because your have a text file that looks like this:

My Hypothetical Text File wrote:Subject: This is my subject
Content: Yup, pretty awesome content.


Does not mean that This is my subject will be parsed into the metadata of the file so that programs like Hazel can read it.

And if you are looking for just three keywords in the content of the file, it's pretty easy. You do not have to create separate rules:

Code: Select all
if (any) of the following conditions are met for (the file or folder being processed):
     Contents contain X
     Contents contain Y
     Contents contain Z

Do the following to the matched file or folder:
     …


Or:

Code: Select all
if (any) of the following conditions are met for (the file or folder being processed):
     Contents contain Tomato
     Contents contain Lettuce
     Contents contain Mushroom

Do the following to the matched file or folder:
     …
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

The "duh" was me acknowledging my stupidity in asking about a "subject" for a text file. I was thinking within the framework of nvALT, where you can have a subject (or, really, a "name") for a file, and then separate contents for the file. But, of course, in those terms, the subject (or name) in nvALT is really just the name of the text file. That was bad thinking on my part. Got it. My bad.

As far as the searching on multiple keywords goes...I'm not suggesting that it's at all hard to do multiple searches; only that it's easier to do one single search for multiple words. My fingers have to move around less (and not drift to the mouse) if I can just set up one search field and have it search for "X or Y or Z or A or B or C" rather than six separate searches for X, then Y, then Z, etc.... , where on each separate search I also have to take the time to change to change the search from "if name is" to "if content contains."

No big deal. Just a nice-to-have.

- Mark
markewallace
 
Posts: 6
Joined: Sun Feb 17, 2013 10:49 pm

Understood. :-)

If you are comfortable with scripting, there are certainly ways that you could implement a single-line boolean search.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Concept-wise, I'm comfortable with scripting; however, I'm coming from an old DOS/Windows background and am *very* new to the Mac world.

Apple Script and Automator is something that I would like to learn eventually, but I have no ability in that area right now on the Mac.

/mew
markewallace
 
Posts: 6
Joined: Sun Feb 17, 2013 10:49 pm

Allowing "X or Y or Z" is not a good idea. I've tried very hard to prevent the use of syntax in anywhere in Hazel except for in scripts. The problem with doing "X or Y" is that "or" becomes special so if someone wants to search for the literal text "X or Y", you would have to introduce syntax to escape it to distinguish it from the special meaning of "or". And then you would introduce syntax to escape the escape characters. It's important that the text fields always represent the actual text you are matching. If you want to introduce programming constructs, then I suggest doing it in a script.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Yeah, I get that. Still, concept-wise, that's what I'm looking for. I guess, in essence, a faster way to do "X or Y or Z" than having to go independently set up separate searches, which isn't horrible, but is slower than it probably could otherwise be.

Food for thought I guess for future updates.

/mew
markewallace
 
Posts: 6
Joined: Sun Feb 17, 2013 10:49 pm

Unless you are seeing a performance problem, I wouldn't worry about that aspect. Searches are done via Spotlight (so terms are indexed) and they are cached across files (so it's usually only done once per search term per run, not per file).
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support