Also from Reddit, a nice little hack that allows you to automatically add a downloaded file’s URL as a Spotlight comment to the file itself. Spotlight comments are useful because they add metadata to a file, and they are supported across many 3rd party applications such as DEVONthink, Leap and Launchbar.
Spotlight comments are searchable, and having a URL automatically attached to a downloaded file can come in handy when you remember the website you downloaded something from, but you can’t find the file.
To automatically add a URL as Spotlight comment, fire up AppleScript Editor (located in Application/Utilities) and paste the following code:
on adding folder items to thisFolder after receiving someItems
if (count items of someItems) ≠ 1 then return
set itemAlias to (item 1 of someItems) as alias
do shell script "mdls " & (quoted form of (POSIX path of itemAlias))
set urls to the result
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"kMDItemWhereFroms"}
try
set urls to (text item 2 of urls)
set AppleScript's text item delimiters to {quote}
if (count urls's text items) ≤ 3 then
set urls to (text item 2 of urls)
else
set urls to (text item 4 of urls)
end if
set myFile to itemAlias as string
tell application "Finder"
set the comment of file myFile to urls
end tell
on error
set AppleScript's text item delimiters to oldDelimiters
return -- urls don't exist
end try
end adding folder items to
Then save the file as a Script into the Folder Action directory ~/Library/Scripts/Folder Action Script, where “~” is your user folder.
Next, open Folder Action Setup either by right-clicking on the folder where your downloaded files will end up in and selecting Services > Folder Action Setup, or manually opening the app located into Mac HD/System/Library/Core Services.
In Folder Action Setup, select the destination folder on the left and the script you just created on the right. Now, every time your browser will save a file in that folder, a Spotlight comment with the source URL will be added to the file, making it searchable in apps that support Spotlight comments.
I’ve personally tested this in DEVONthink and it works great.