This Week's Sponsor:

Kolide

Ensures that if a device isn’t secure it can’t access your apps.  It’s Device Trust for Okta.


Tip: Automatically Add URL To A Downloaded File As Spotlight Comment

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.

Unlock More with Club MacStories

Founded in 2015, Club MacStories has delivered exclusive content every week for over six years.

In that time, members have enjoyed nearly 400 weekly and monthly newsletters packed with more of your favorite MacStories writing as well as Club-only podcasts, eBooks, discounts on apps, icons, and services. Join today, and you’ll get everything new that we publish every week, plus access to our entire archive of back issues and downloadable perks.

The Club expanded in 2021 with Club MacStories+ and Club Premier. Club MacStories+ members enjoy even more exclusive stories, a vibrant Discord community, a rotating roster of app discounts, and more. And, with Club Premier, you get everything we offer at every Club level plus an extended, ad-free version of our podcast AppStories that is delivered early each week in high-bitrate audio.

Choose the Club plan that’s right for you:

  • Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with app collections, tips, automation workflows, longform writing, a Club-only podcast, periodic giveaways, and more;
  • Club MacStories+: Everything that Club MacStories offers, plus exclusive content like Federico’s Automation Academy and John’s Macintosh Desktop Experience, a powerful web app for searching and exploring over 6 years of content and creating custom RSS feeds of Club content, an active Discord community, and a rotating collection of discounts, and more;
  • Club Premier: Everything in from our other plans and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.