I am trying to add comment in files and directory programmatically.
Is it possible to do? If yes, please help me to achieve this.
I looked for a direct API from Cocoa framework but no success, I will be happy to do this by any way (cocoa, shell or any scripts).
AFAIK there is no public API, if you google for Spotlight comments you will see various solutions which all are based on AppleEvents, Applescript or xattr.. like
http://www.cocoabuilder.com/archive/cocoa/178663-writing-spotlight-comments.html http://www.cocoabuilder.com/archive/cocoa/305493-adding-spotlight-comment-data-to-folder-file.html http://cocoadev.com/SpotlightAndTagging
I achieved this by Apple Script wrapped in Objective-C as :