Restoring Missing Spotlight Comments
Apr 20th, 2007 by tortoise
This is a post for those of us on a Mac with metadata/tagging issues.
There are times when Spotlight Comments disappear from a file’s Get Info box, and they aren’t really gone. You can check this in Terminal. Say I have an Apple Chowder recipe file with an empty comments box. First, I open Terminal and type in mdls and a space, then select the recipe file and drag it into the Terminal window (so I don’t have to type in the filename). I end up with the following command:
mdls /Users/tortoise/Documents/recipes/apple\ chowder.rtf
I hit enter and get something back like this
/Users/tortoise/Documents/recipes/apple chowder.rtf -------------
kMDItemAttributeChangeDate = 2007-04-20 03:41:14 -0400
kMDItemContentCreationDate = 2007-01-28 21:47:43 -0500
kMDItemContentModificationDate = 2007-01-31 17:06:51 -0500
kMDItemContentType = "public.rtf"
kMDItemContentTypeTree = ("public.rtf", "public.text", "public.data", "public.item", "public.content")
kMDItemDisplayName = "apple chowder"
kMDItemFinderComment = " &recipe &breakfast"
kMDItemFSContentChangeDate = 2007-01-31 17:06:51 -0500
kMDItemFSCreationDate = 2007-01-28 21:47:43 -0500
kMDItemFSCreatorCode = 0
kMDItemFSFinderFlags = 16
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 1
kMDItemFSLabel = 0
kMDItemFSName = "apple chowder.rtf"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 502
kMDItemFSOwnerUserID = 502
kMDItemFSSize = 1638
kMDItemFSTypeCode = 0
kMDItemID = 2880424
kMDItemKind = "Rich Text Format (RTF) document"
kMDItemLastUsedDate = 2007-01-31 17:06:51 -0500
kMDItemUsedDates = (2007-01-31 17:06:51 -0500)
I look for the kMDItemFinderComment line, which shows tags for the file (in this case, “&recipe” and “&breakfast”). If the file had no tags, the line would not exist. It does exist in this case which means that the tags are still with the file, they just aren’t showing.
Another way to find the tags is to type “mdls” and a space into the Terminal window, drag the file into the window, then type ” | grep FinderComment”, like so:
mdls /Users/tortoise/Documents/recipes/apple\ chowder.rtf | grep FinderComment
This serves to isolate just the info we want and not all of the Spotlight metadata, and our result (after pressing enter) is this:
kMDItemFinderComment = " &recipe &breakfast"
If my file had no tags, I’d just get a Terminal command line.
The bad part about disappearing tags is that if I opened the Get Info window and typed in some new tags for this file, it would overwrite the tags that are already there. Most annoying. Especially when working with a bunch of files. So it’s important to restore the tags.
How to get the comments back into the Get Info window? I started tackling the problem with AppleScript, but … whew. My geek skills were inadequate for the task. Then I found TagBot. The program isn’t free, but you can use 6 tags with it without registering.
In TagBot’s Tag Palette, I created a tag with the most unique name possible: — a28nine — so it wouldn’t match any of my existing tags. I then selected all the files with the “missing” comments and dragged them onto the TagBot a28nine tag in the palette. TagBot restored the original tags and added the a28nine tag. I then had TagBot remove the a28nine tag from all files (by selecting ctrl-clicking on the tag in the palette and choosing the “Remove From All Files” option).
Tada! No applause necessary. Just go out and spread the word. TagBot.
Did you ever find out why on earth this situation arises? Can’t find anything about it on apple.com. Seems to me it happens every few weeks or so. Last time, I re-tagged all my files. Happened again today, but at least your trick saved me all the hard work.
Thanks!
I forget where I read why it happens, but I think it had something to do with how you move/copy files. For instance, moving files with Hazel can “erase” Spotlight comments.
Hmmr, weird. I havn’t moved files in a while. I dump everything in Documents, and tag it appropriately. This is driving me nuts!
I think I found an answer to why it’s happening. According to the second entry at this forum post, “… spotlight comments live in the hidden .ds-file. So one has to make sure to keep t when doing backups or transferring files. Would not work via: mac-windows-pc-mac. …”
Oh man, that’s it. Makes total sense. I use Cocktail (http://www.maintain.se/cocktail/index.php) to run some maintenance tasks, and one of the software’s features is to hunt down and delete .DS* files.
That has to be it. I stopped using that function a while ago (switched to PathFinder, I highly recommend it) and my tags have not disappeared.
Good find!
There is a very easy way to restore Spotlight comments built right into OS X Finder.
Open System Preferences, Spotlight, Privacy
Drag folder containing files with missing comments to the list. This will instruct Spotlight to stop indexing the content of the folder.
Now, remove the folder from Privacy listing. This will force reindexing of its content by Spotlight. Once completed, select any previously commented file inside reindexed folder, Get Info to confirm that Spotlight Comments are back where you want them.
You are a Saint for posting this! I would have lost a months worth of data hadn’t I found this posting.
I tried the other method (using privacy settings in Spotlight) however it did not recreate all of the comments in all of the files.
Thank-you very much!