Hazel app has this property "Source URL/Address" which is the same information as "Where from" value in "Get info" in the contextual menu of a file. It is the actual url from where file was download. (Hazel wont accept my credit card so I have to find alternative).
Can't post screenshot coz new here.
Does anyone know how to access this "Where from" value through AppleScript (or automator or kayboard meastro)? If Hazel can do it why cant AppleScript?
You can use the mdls
command to get a file's metadata attributes. Typing mdls filename.txt
in the terminal will show you all of a file's metadata. Using the -name
option you can specify the key you want. The "Where from" metadata has the key kMDItemWhereFroms
so, for example:
$ mdls -name kMDItemWhereFroms ~/Downloads/boop.gif
kMDItemWhereFroms = (
"http://25.media.tumblr.com/0dfb82efe15f409dd4b5c5e20835509a/tumblr_msv0ysmBIB1r3gb3zo1_400.gif",
""
)
You can use the -raw
option to get only the value:
$ mdls -name kMDItemWhereFroms -raw ~/Downloads/boop.gif
(
"http://25.media.tumblr.com/0dfb82efe15f409dd4b5c5e20835509a/tumblr_msv0ysmBIB1r3gb3zo1_400.gif",
""
)
In this case the file has two "where froms," one of which is an empty string. Who knows why that is. Other files I've tried have one just one, an some have multiple URLs, which seems to result from redirects. Files with no such metadata will return (null)
, but it's configurable—read the man page for that.
To use this in AppleScript you can do like so:
set theFile to (choose file)
set thePath to quoted form of POSIX path of theFile
do shell script "mdls -name kMDItemWhereFroms -raw " & thePath
You'll have to parse the output, but that doesn't seem too tough.