Frederick said:
It's a little more tricky writing to these: to write a finder comment
(now called spotlight comment, but implementation-wise it's the same)
you need to send an appleevent to the finder (there'a a code sample on
developer.apple.com for this).
You can do AEs from C but it's a bit tedious. Much easier with a
high-level bridge, e.g.:
require "appscript"
pth = "/path/to/some file or folder"
txt = "some comment"
AS.app("Finder").items[MacTypes::Alias.path(pth)].comment.set(txt)
Or, if you want to avoid dependencies and speed isn't an issue, you
could just use osascript to invoke an AppleScript via the command line.
Kludgy, but it'll do the job.
If portability is a must though, bear in mind that some OS X users run
third-party file managers in place of the Finder. (Not like the ol' OS
7-9 days when Finder availability was pretty well guaranteed.) I think
there's also some very crusty Carbon APIs for accessing Finder-related
data, though can't remember anything about them. Probably in the Carbon
File Manager or somewhere like that.
For querying files, the OP might also want to check out the Carbon or
Cocoa Spotlight APIs:
http://developer.apple.com/documentation/Carbon/Conceptual/SpotlightQuery/index.html
There's a 'RubySpotlight' example included with RubyCocoa 0.4.2 that
may be of help here.
has