Firefox WhereFrom/Source URL Metadata

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Firefox WhereFrom/Source URL Metadata Mon Apr 15, 2013 5:21 pm • by a_freyer
Well, since lots of people have been asking about this, I figured I'd whip up something quick. This works to add Firefox WhereFroms:

This was faster than building the query, but it's a bit hacky:

First you have to find your firefox user profile's downloads database, mine was here: /Users/MYUSERNAME/Library/Application Support/Firefox/Profiles/NUMBERSandDIGITS.default/downloads.sqlite

Then a rule:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     <Distinguish Firefox Downloads However You Want To>
     Source URL is Blank

Do the following to the matched file or folder:
     Run Embedded Script


Embedded Script:
Code: Select all
WhereFroms=$(/usr/bin/sqlite3 "/Users/MYUSERNAME/Library/Application Support/Firefox/Profiles/NUMBERSandDIGITS.default/downloads.sqlite" .dump | grep -i "$(basename "$1")" | awk -F "," '{print $3}' | sed "s/'//g")

xattr -w com.apple.metadata:kMDItemWhereFroms "(\"$WhereFroms\")" "$1"


EDIT - Array format added for WhereFroms
Last edited by a_freyer on Tue Apr 16, 2013 9:30 am, edited 1 time in total.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Firefox WhereFrom/Source URL Metadata Mon Apr 15, 2013 9:53 pm • by north45
thanks so much! I haven't tried this yet and I'm running out the door at the moment, but I will report back tonight.
Cheers!! it's much appreciated.
north45
 
Posts: 4
Joined: Mon Apr 15, 2013 11:39 am

Re: Firefox WhereFrom/Source URL Metadata Tue Apr 16, 2013 6:27 am • by north45
ok, so I tested this out and it did successfully get the "where from" metadata written for the image I used to test it. However, when I tried to get Hazel to perform an action using a "source url / address rule" based on that metadata, I got the following error:

Image

(I had named the hazel rule in question, inelegantly, "test for the thing"; the picture I was using to test it was karelian.jpg)

any thoughts on what's going on there?
north45
 
Posts: 4
Joined: Mon Apr 15, 2013 11:39 am

Re: Firefox WhereFrom/Source URL Metadata Tue Apr 16, 2013 9:30 am • by a_freyer
Looks like Hazel expects the Array format for the WhereFroms. Use this (I updated above too):

Code: Select all
xattr -w com.apple.metadata:kMDItemWhereFroms "(\"$WhereFroms\")" "$1"
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Firefox WhereFrom/Source URL Metadata Wed Apr 17, 2013 7:57 am • by north45
I edited the script as you said to, but still got the same error message.

I am starting to think this is impossible even though it seems so simple!

Thanks for your help I do appreciate the effort. Let us know if you figure anything new out.
north45
 
Posts: 4
Joined: Mon Apr 15, 2013 11:39 am

Re: Firefox WhereFrom/Source URL Metadata Wed Apr 17, 2013 8:19 am • by a_freyer
What are your rule actions and conditions?
Last edited by a_freyer on Sun May 12, 2013 10:23 pm, edited 1 time in total.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Firefox WhereFrom/Source URL Metadata Wed Apr 17, 2013 12:36 pm • by a_freyer
I've confirmed that this works with multiple actions and conditions. Without more information from you I'm not sure we can solve your issue.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Firefox WhereFrom/Source URL Metadata Fri Apr 19, 2013 1:13 pm • by jafwld
Thank you for sharing this Hazel script with the forum! It works no problems on my end and if I have to be completely honest I didn't expect it to truly work the first go around. Well played sir, well played.
jafwld
 
Posts: 1
Joined: Mon Jan 28, 2013 3:38 pm

Re: Firefox WhereFrom/Source URL Metadata Sun May 12, 2013 10:12 pm • by kirkbond
I want to extend my thanks as well. I hit a wall with Hazel doing what I needed it to do and this blasted right through it!!!!!!!

Would never have figured that out by myself.

Thanks again.
kirkbond
 
Posts: 5
Joined: Sun May 12, 2013 10:10 pm

URL blank? Tue May 28, 2013 1:05 pm • by greenery
So I've been trying to get this to work because I download a lot of work stuff through Firefox. I've had only partial success. I think my problem is here:

Source URL is Blank


I'd like Hazel to grab a wide variety of file types and folder that have been downloaded from one specific website. How do I do that while leaving the Source URL blank?

I'm still in my evaluation period, and hoping to be able to work this out because otherwise, I really like Hazel.
greenery
 
Posts: 3
Joined: Sun May 26, 2013 12:11 pm

Re: Firefox WhereFrom/Source URL Metadata Tue May 28, 2013 1:09 pm • by a_freyer
greenery wrote:So I've been trying to get this to work because I download a lot of work stuff through Firefox. I've had only partial success. I think my problem is here:

Source URL is Blank


I'd like Hazel to grab a wide variety of file types and folder that have been downloaded from one specific website. How do I do that while leaving the Source URL blank?

I'm still in my evaluation period, and hoping to be able to work this out because otherwise, I really like Hazel.


I'm confused by this question. Firefox does not assigne SourceURL data, so SourceURL will always be blank for any file downloaded from Firefox.

Can you expand a bit?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Firefox WhereFrom/Source URL Metadata Tue May 28, 2013 1:23 pm • by greenery
Of course, and thanks for getting back to me so quickly. As you've already noticed, I am not a programmer by any definition of the word and I will garble things in direct proportion to my level of confusion. But I'll try to be clear.

I use Firefox. There's a website from which I regularly download zip folders full of small mod files, txt, php, cfg, for the most part. Right now I have it set up so the zip unpacks itself.

I'd like to have Hazel move all these folders/files from a specific domain to a specific location, and so I experimented for a good amount of time on that, primary by using the source domain url in the hope that anything downloaded from within that domain would trigger the Hazel rule and end up in the right location.

After a stunning lack of success, I started looking through the forum and came across this thread. I took the discussion to mean that the problem I was having originated with Firefox, and could be fixed.

Maybe I've got it all wrong. If so, please let me know. And thanks again.
greenery
 
Posts: 3
Joined: Sun May 26, 2013 12:11 pm

Re: Firefox WhereFrom/Source URL Metadata Tue May 28, 2013 1:38 pm • by a_freyer
You will need a custom solution, unfortunately.

Here's the second problem: when you unarchive a file, the uncompressed files do not inherit the WhereFrom (source URL) attribute that their zip might have otherwise had.

So, you have a two-part problem. First, Firefox does not add WhereFrom data, so Hazel can't use that data for actions related to the zip file itself, and second, even if you use my trick posted above, Finder does not add that metadata once you've unzipped the file.

To actually add the metadata to these files, you're going to need a script or many rules. A single script will take time to write. However, if you are only interested in moving files from a particular domain to a particular folder, with limited scripting knowledge, what I would suggest is to inject intermediate steps.

(1) Download the Zip File
(2) Run the script above to add WhereFrom data to the Zip
(3) Create a folder somewhere named the WhereFrom of the Zip
(4) Extract the content of the Archive into the WhereFrom created by the Zip
(5) Another rule dives into these "wherefroms" files and runs this script as an embedded script:

Code: Select all
xattr -w com.apple.metadata:kMDItemWhereFroms "(\"$(basename $(dirname "$1"))\")" "$1"


(6) Now, you can move the files to your main sort directory which includes your rules for moving based on the domain.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Firefox WhereFrom/Source URL Metadata Tue May 28, 2013 2:29 pm • by greenery
It's an odd thing to say, but I'm almost glad it's so complicated. At least I didn't miss something really obvious.

When I have time later today or tomorrow, I'll see if I can make this work. It's very good of you to go to so much trouble. Many thanks.
greenery
 
Posts: 3
Joined: Sun May 26, 2013 12:11 pm

Re: Firefox WhereFrom/Source URL Metadata Tue May 28, 2013 3:16 pm • by a_freyer
If I have the time, I'll type out a full tutorial and put it here. This is likely something that other folks are interested in this as well.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Next

Return to Tips & Tricks - DO NOT POST QUESTIONS