Spotlight comment via command line?

Hi all

Anyone knows whether it is possible to add a spotlight comment to a file/folder with a shell command? And if it is, what this command is? I tried GetFileInfo to at least read a spotlight comment, but it didn't show it.

Tina

G5 Dual 1.8, 23'' Cinema Display, Mac OS X (10.4.5), iMac G4/800, iBook G3/700, G4/400, iBook G3/366, iMac G3/233, PM 7200, Mac SE

Posted on Oct 9, 2007 8:51 AM

Reply
7 replies

Oct 9, 2007 11:26 AM in response to Tina Siegenthaler

"Finder" comments aren't very reliable so it probably is best to avoid them for anything important if possible. They aren't actually a part of the file, and in the case of "OS X", they are stored in the ".DS_Store" files of the folder in which the file resides. The ".DS_Store" files aren't always updated in a timely manner and if anything disrupts the association between the file and the ".DS_Store" file containing that file's comments, the comment may be lost. For example, most command line methods of copying or moving files will not transfer the "comment" unless the whole folder is processed together. There is even some ambiguity, where moving a file with 'mv' updates the Spotlight database so that it appears as if the comment moved along with the file, when in fact it hasn't.

Anyway, regarding the original question, the only way I know of to add a comment via the command line is indirectly - i.e. using ' osascript' to get AppleScript to tell the "Finder" to do it. This obviously isn't ideal since a user with sufficient privileges to modify the ".DS_Store" file associated with the item has to be logged in and the "Finder" has to be running. eg.<pre>
osascript -e 'tell application "Finder" to set comment of (choose file) to "blah"'</pre>

Oct 10, 2007 3:00 AM in response to biovizier

Hmm. This may be a possibility.
Maybe I should give a short explanation on why I want to do this... We have a Mac OS X Server hosting home directories for students who are doing a course at our institute. We need to have all those homes in just one location (don't ask why). I'd now like to add some attribute to the homes so to know which homes belong to students of which course, to make it easier to delete them when a course ends. I started to use Finder labels, but I'm running out of label colors...
I create the homes using a shell script, and of course it would be easiest to set that "attribute" with the course number also with that same script. I won't move around the homes, so it will probably not be a problem that the comment is not actually part of the file.
Any other ideas on how to distinguish those homes? Can't add something to their names, though.

Tina

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Spotlight comment via command line?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.