193 symposiums and 30,000 attendees since 2001

AppleScript to Re-Apply Finder Comments

Posted by: Matthew McCullough on 01/25/2010

Finder Comments Lost

When restoring from a backup, depending on the Mac-specific intelligence of your backup solution, or when copying files written by a 10.4 Mac, your Spotlight (Finder) Comments stored in the .DS_Store files might not survive the round trip. You’ll first notice this by the fact that your comments field or column is completely empty for files you know you previously tagged or made comments on.

Leopard, Snow Leopard Comment Storage

Tiger and previous editions of Mac OSX store Spotlight comments in the .DS_Store file exclusively. Leopard and Snow Leopard on the other hand, claim to maintain backwards compatibility by storing the Spotlight Comments in both the .DS_Store and the new Extended File Attributes. I question this thinking though, because Mac OSX developer Steve Gehrman of the awesome PathFinder team says that Finder, while it writes both formats, still only reads back the .DS_Store ones. It seems to me that Apple would have changed Finder to read from the newer Extended Attributes as soon as they started writing to those in duplicate.

“On Mac OS X 10.4 Tiger, for example, .DS_Store files also contain the Spotlight comments of all the folder’s files, whereas Mac OS X 10.5 “Leopard” stores this information in Extended file attributes.”

Script Research

Giving a tip of the hat to the similar-but-not-quite-what-I-wanted script that helped me get enough of the syntax working (using type alias instead of type file was tricky) get my own authored, I give you:

A MacOSXHints article, and the corresponding code

The Solution

To solve this extended attributes vs. .DS_Store discrepancy, we only need to read (from the extended attributes) and reapply (thereby recreating the .DS_Store) the same comment. The solution is this AppleScript. Just highlight the files needing the treatment in Finder, then execute this script from the AppleScript Editor.

The result is that Finder (which reads only the .DS_Store files) and PathFinder (which only reads the extended attributes) can both now see the Spotlight Comments.

Extras

If you would like your Mac to automatically clean up the .DS_Store files it writes out to flash sticks and network drives, check out BlueHarvest, an interesting little utility app that fills this need.


  • Currently 5.0/5
  • 1
  • 2
  • 3
  • 4
  • 5
5.0 rating out of 1 votes

About Matthew McCullough

Matthew McCullough

Matthew McCullough is an energetic 12 year veteran of enterprise software development, open source education, and co-founder of Ambient Ideas, LLC, a Denver consultancy. Matthew currently is a member of the JCP, reviewer for technology publishers including O'Reilly, author of the DZone Maven RefCard, and President of the Denver Open Source Users Group. His experience includes successful J2EE, SOA, and Web Service implementations for real estate, financial management, and telecommunications firms, and several published open source libraries.

Matthew jumps at opportunities to evangelize and educate teams on the benefits of open source. His current interests are Cloud Computing, Maven, iPhone, Distributed Version Control, and OSS Tools.

Matthew resides in Denver with his beautiful wife and baby daughter, who all are active in nearly every outdoor activity Colorado offers.

More About Matthew »

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Core Java, JEE
  • Groovy, JRuby, Scala, Clojure
  • Hibernate, Grails, Spring, JSF, GWT
  • Ajax, Flex, RIA
  • more...
Learn More »

NFJS, the Magazine

December Issue Now Available
  • Hibernate Performance Tuning, Part 2
    by Scott Leberknight
  • Virtualization for Development
    by Pratik Patel
  • Emergent Design & Evolutionary Architecture
    by Neal Ford
  • Writing Secure Code with ESAPI
    by Ken Sipe
Learn More »