Hmm… Aha…

stuff might interest somebody

Posts Tagged ‘add-on’

Add ‘Where from:’ to Firefox downloads (Mac OS X)

Posted by f3lix on January 9, 2009

If you used Safari before you switched to Firefox, you might miss Safari’s feature that annotates each download with the URL it was downloaded from.  So if you find file in Download folder and wonder where it came from, you use Finder (“File > Get Info” or CMD+I) to show it’s source URL. Or if you like the shell, you can use the mdls command-line tool to get the info:

#> /usr/bin/mdls -name kMDItemWhereFroms a_downloaded_file.pdf
kMDItemWhereFroms = "http://www.example.com/paper.pdf"

Manually setting the “Where From:” URL

Today I asked myself if there was also a way to write this data. I did a little research on the web and found out the “Where From”-URL is actually saved in as an extended attribute. Extended attributes can be manipulated with the xattr command. So you can specify the URL for a file by running

/usr/bin/xattr -w com.apple.metadata:kMDItemWhereFroms 'http://www.example.com' <filename>

Make Firefox to set kMDItemWhereFroms

Now, what we really want is to have Firefox set the kMDItemWhereFroms property for us automatically. As I’m not familiar with programming Firefox extensions. I decided to modify an existing one: Download Statusbar 0.9.6.3. I only had to write the following function, add it to the Downbar.prototype in downbar.js and call it from the db_finishDownload function.

    db_SetMetadata: function(aDownload) {
        var cmd = '/usr/bin/xattr'
        var execFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
        
        // Arguments must be separated into an array
        var args = ['-w', 'com.apple.metadata:kMDItemWhereFroms', "'"+aDownload.source.spec+"'", aDownload.targetFile.path ];
        
        execFile.initWithPath(cmd);
        if (execFile.exists()) {
            process.init(execFile);
            process.run(false, args, args.length);
        }
    }

You can also download a patch at http://pastebin.com/f3f4ef81


Edit: for download bar 0.9.7.1 the patch is a tiny bit different. see http://pastebin.com/PbtdGNSU


Posted in Mac OS X | Tagged: , , , , | 7 Comments »