Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: See where Safari downloads originated' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: See where Safari downloads originated
Authored by: fractacular on Jun 17, '05 11:13:01AM
This hint describes how Safari stores the URL of a download in the file's metadata. However, it neglects to mention that you can't copy the information when you get info in the Finder -- how rude!
I wrote a short shell script which displays all the URLs Safari stores in the "Where from" field (more than one URL, sometimes, it seems), and copies the first one to the clipboard. As a scripting novice, I welcome suggestions.

geturl.sh:

#!/bin/sh
# Gets the stored URL(s) of a file you downloaded, 
# prints out all of the metadata it gets
# and copies (to the clipboard) the first URL in the series
mdls -name kMDItemWhereFroms $1 | cut -s -d \" -f2 | head -n1 | pbcopy
mdls -name kMDItemWhereFroms $1 | cut -s -d \" -f2 

Once you've saved this in a file and made it runnable:
chmod 755 geturl.sh
run it on any downloaded file:
geturl Desktop/mydownload.foo


[ Reply to This | # ]
10.4: See where Safari downloads originated
Authored by: SteveJ098 on Jan 09, '10 09:22:19PM

This loop will process multiple files, print the URL's to the tty and save to the pastebuffer
(Quoting of $@ and $f is very important):

#!/bin/sh

for f in "$@"
do
mdls -name kMDItemWhereFroms "$f"|cut -s -f2 -d\"
done |\
tee /dev/tty|\
pbcopy



[ Reply to This | # ]