Page 1 of 1

Hazel fails to recognize matches in "where from" criteria

PostPosted: Sat Dec 19, 2009 3:45 pm
by torreyce
I'm trying to get a rule to automatically sort media files that I download from multiple websites. I selected the first step in a rule to match only the appropriate media files and the second part of the rule to identify files where the "where from" criteria contains the website URL. I have double-checked that the file's attributes include the full URL address of the file (http://www.websitename.com/folder/file). I only select the "websitename" as the criteria. The rule is not identifying any of the correct files even thought they include the proper website name. If I change the criteria to include the full URL then it finds the file. However, obviously this is a useless fix because the full URL is specific only for that file and I want the rule to identify all files from that website.

Why is this happening? Since I'm typing in the "websitename" with the "contains" specification shouldn't it find the right files even if there are characters before or after the "websitename"? Are there wildcard characters that I should use to specify additional text before or after the keyword?

I'm using Hazel version 2.3.4

Re: Hazel fails to recognize matches in "where from" criteria

PostPosted: Mon Dec 21, 2009 5:17 pm
by Mr_Noodle
Are you using the Spotlight "Where from"? If so, I'd advise not doing that and using the built in "Source URL/Address" attribute instead. "Where from"s are a list of URLs so "contains" in that case means whether one of the entries matches the text you give. The "Source URL" attribute does some logic to hide that from you.

Re: Hazel fails to recognize matches in "where from" criteria

PostPosted: Thu Jul 29, 2010 2:42 pm
by M A V 1 C
I just ran into this same issue. Not a huge issue, but maybe it'd be helpful to have something in the interface that mentions that Source URL/Address will work better. I chose the "Where from" option because of what Get Info showed. Maybe if a preview is run and no match is found, it could mention that a match would be found if Source URL/Address was run.

Again, not a huge issue, just some feedback.

Re: Hazel fails to recognize matches in "where from" criteria

PostPosted: Thu Aug 05, 2010 4:02 pm
by Mr_Noodle
I'll consider it though I think the fact that "Source URL/Address" is in the default set of attributes whereas you have to wade through the list of Spotlight attributes for "Where froms" is in some ways an encouragement to use "Source URL/Address".

Re: Hazel fails to recognize matches in "where from" criteria

PostPosted: Thu Aug 05, 2010 4:33 pm
by torreyce
I would point out that I too used the "where from" attribute because that is the language that you see when you choose Get Info. That is what traped me as well.

Re: Hazel fails to recognize matches in "where from" criteria

PostPosted: Thu Aug 05, 2010 5:52 pm
by sjk
Hope no one minds if I piggyback on this topic with something it reminds me of …

I'd like to create a Hazel rule that grabs the first URL of "Where from" (kMDItemWhereFroms) metadata (if it exists) and appends it to the file's Spotlight Comments (kMDItemFinderComment) metadata.

Seems necessary to do it entirely with a script, especially the first part. There's an "Add comment" action in Hazel but I don't know if/how it's possible to use the result of the first-part script for its value.

I can use the mdls command to obtain kMDItemWhereFroms, e.g.:
Code: Select all
% mdls -name kMDItemWhereFroms Ingredients_1.0rc1.zip
kMDItemWhereFroms = (
    "https://fileabilcloudfront.s3.amazonaws.com/Ingredients_1.0rc1.zip",
    "http://fileability.net/ingredients/"
)
… but the result isn't in an ideal format to easily grab the first URL.

Any suggestions for a clean/optimal way to do this, with minimal programming (I don't know much beyond shell scripting), would be appreciated -- thanks!

Re: Hazel fails to recognize matches in "where from" criteria

PostPosted: Thu Aug 12, 2010 3:18 pm
by Mr_Noodle
I am looking to add support for patterns in the "Add comment" action in a future release but in the meantime, I think something like 'sed' should do what you want.

Re: Hazel fails to recognize matches in "where from" criteria

PostPosted: Thu Aug 12, 2010 11:45 pm
by sjk
Thanks for the feedback. Your mentioning 'sed' inspired me to look for an old script I remembered writing to do this. Found it, the meat being:
Code: Select all
mdls -name kMDItemWhereFroms "$@" | cut -d '"' -f2 -s | head -n 1

Inelegant, but functional. Using 'sed' probably won't be pretty either, but saves a process. :)

Re: Hazel fails to recognize matches in "where from" criteri

PostPosted: Fri Jan 06, 2017 7:39 am
by snorbaard
Sorry to resurrect this old post, but I'm starting to dabble in the Hazel automation field, and I have a particular file (an invoice) that I have to open an email and click on the "Download Invoice" button that then just downloads the PDF immediately.

For whatever reason (Sierra?), the only "More Info" I get is the "Where From" field:

Image

I've worked with the above examples, and the only useful information from the mdls command is (obviously) kMDItemWhereFroms.

My hacked-together condition is thusly:
Code: Select all
if [ `mdls -name kMDItemWhereFroms $1 | cut -d '"' -f2 -s | head -n 1 | grep "https://clientzone.afrihost.com/en/billing" ` ]; then
   exit 0
else
   exit 1
fi


Image

Change the text in grep to your taste.

Since we're at Version 4 of Hazel since this original question came up (v2), is there any support planned for this subsection of metadata to make it as easy to use as Source URL/Address? It really scrambled my rusty brain for a bit trying to get to the answer, and is a high barrier to entry.

Re: Hazel fails to recognize matches in "where from" criteri

PostPosted: Fri Jan 06, 2017 12:10 pm
by Mr_Noodle
Source URL/Address is the easy to use version of Where froms. It is backed by the same data. Do note that Where froms is a list, not just a singular value. Hazel simplifies that with the Source URL attribute.