Spotlight comments to document notes/synopsis

An option in the Scrivener preferences to copy a file’s spotlight comments either to the synopsis or the document notes in Scrivener on import (drag-and-drop and import command) would make life a lot easier for me.
Usage scenarios are abundant. One is better integration with DevonThink. DevonThink’s new Safari PlugIn offers to possibility to attach a note to a captured webpage. This note is saved as spotlight comment. It would be great to drag such an annotated DevonThink clip (PDF, RTF, or Webarchive) to Scrivener and have the note as synopsis, for example.

I don’t think there’s an easy way to access that information, although I could be wrong. There are no plans for this at the moment, but you can always suggest it again around 2.5 when more major features are out of the way and stable.
Best,
Keith

I do not cocoa but I do applescript…

set myfile to choose file tell application "Finder" to set comment of myfile to "hello world!"

There is no Cocoa command for this - I just did a quick dev search and other developers have to call on AppleScript to add Spotlight comments to files. Likewise there is no Cocoa access for reading the Spotlight comments of files. Presumably AppleScript would have to be used for that too (assuming you can read the comments of files using AppleScript), so it’s not exactly graceful. As I say, I’ll happily look at this again next year maybe, but right now it’s not something I want to get into, sorry!

All the best,
Keith

This is interesting and somehow baffling, given that comments are exposed in the Finder’s info dialog, and via the spotlight architecture. It is difficult to understand why there should be no cocoa class capable of reading spotlight metadata. Internally, the comments are called kMDItemFinderComment.

Just for future reference, in case you decide one day to come back to this. If there is really no direct way, you should be able to run unix programs in the shell via Cocoa’s NSTask.

To read Spotlight comments, use mdls:

mdls -name kMDItemFinderComment -raw ~/path/to/my/file

If you also would want to write Spotlight comments for any reason, use osascript:

osascript -e 'tell application "Finder" to set comment of (POSIX file "/path/to/my/file" as alias) to "hello world!"'

Thanks for the info. Yes, Spotlight is really under-exposed right now. About all you can do with Cocoa is write a Spotlight plugin (basic, for allowing your app to show custom information in Spotlight) and invoke the QuickLook panel - as a black box - in your app (10.6 only). (I really wish Apple would add a QuickLook view to Cocoa, so that I could have a QuickLook view for viewing arbitrary files in Scrivener’s editor, but currently you are limited only to a panel - DevonThink have hacked it, but even then you are only allowed one panel per application and so you can’t have two QuickLook views at the same time in the same app as Scrivener would need… Er, but that’s off-topic).

As for kMDItemFinderComment, it does look as though this may be available via some Carbon methods - I’ll have a play at some point, but only post-2.0 - no time at the moment! (It would be of limited use to most users anyway, I imagine.)

Thanks,
Keith

looking for something else, I found this:
developer.apple.com/library/mac/ … rence.html

just for future reference
xaxa

Hi Mark, I’m aware of that - that’s actually what I was referring to above, when I mentioned kMDItemFinderComment (which is declared on the page you link to). MDItem is for generating or viewing QuickLook previews, not for manipulating file data - as I say, that would have to be done using Carbon.