Finder comments without finder

I’ve seen multiple times, the Finder doesn’t write comments to files reliably, no matter what OS I have been using.

tell application "Finder" to set comment of getFile to "Test" 

What I wanna say is, sometimes the “Finder” writes, sometimes it doesn’t, even if the input is declared as string.

Adding tags would be another way to add the info to my files, but because the content of my comments varies very much, i only would spam my tag list.
Is it actually possible to write to file comments without the Finder?

Shane have made ASObjC code to set tags if you search on

I stop after 3 doing search on

If you look in Dictionary of Finder,

It calls: Spotlight Comments

I’m not convinced that’s the case. My guess is that the Finder writes to, and reads from, the containing folder’s .DS_Store folder, and that the Finder’s Spotlight plug-in reads comments from there when creating the corresponding Spotlight kMDItemFinderComment metadata item.

Maybe the name use to be Spotlight Comments, but I got the name from Automator Action
made by Apple to set comments in Finder Items.

Automator Action: Set Spotlight Comments For Finder Items version 1.1.1
The copyright say 2004-2012

I misunderstood what you were saying. Spotlight has its own Comments key (kMDItemComment), and I thought you were referring to that.

That action has a strange name…

I also did a example of Comments… and compare .DS_Store before and after.

You are right that Finder store comments in .DS_Store… I could see it from text editor.

I refer to text in my first post :

None of the example links given show how to apply comments without the Finder.
Scripters who interact with the file system know the Finder is slow and unreliable. In fact, I’d not need to ask for alternative ways to add comments, as the Finder code to add comments to files is stupid simple. But this stupid simple code is, unfortunately, unreliable

I recommend to read with more attention what people post, English isn’t my first language either

Since file comments are an extended attributes, one way to do it without the Finder could be with xattr, if I’m right. I never used it but it seems to modify files, not file attributes. Just a quick test : (This code doesn’t throw errors but won’t write anything either)

tell application "Finder" to set sel to item 1 of (get the selection) as text
set theW to "Test"
do shell script "xattr -w 'kMDItemFinderComment = \"" & theW & "\"' '" & POSIX path of sel & "'"

The problem with your approach is:

xattr command do not store the ‘Finder Info’ comments the same way Finder does.

If you have any issue with Apple’s products why not report it to them (Apple) instead of trying
to beat someone who are kind enough to help you.


Using xattr will not update Finder info.
But doing it in Finder and Automator its does. (.DS_Store)

Ps. Any create/modified file need to be index with mdworker to be able to show any metadata.

tell application "Finder"
	if ((selection is {}) or ((count of (get selection)) > 1)) then return -128
	set theSelection to its selection
	set thePath to POSIX path of (theSelection as alias)
end tell

set cText to (display dialog "Comments Text:" default answer "")'s text returned

do shell script "xattr -w '' " & "'" & cText & "'" & space & quoted form of thePath & " ; " & "mdimport -i " & quoted form of thePath

delay 5

set status to do shell script "mdls -n kMDItemFinderComment " & quoted form of thePath

display dialog status

	set searchFile to do shell script "mdfind \"kMDItemFinderComment\" == " & "'" & cText & "'"
	display dialog "Search result" & linefeed & searchFile
end try

Be aware that this throws an error if nothing or more than one item is selected.

I would like to see at least one code (involving Finder) that cannot set the comment property of a Finder element. In the meantime, I agree with only one statement: Finder is not fast enough compared to System Events or AsObjC.

Let’s say you edited the .DS_Store of the folder. How does this relate to the comment property of the Finder app? I think so - unidirectionally. I think .DS_Store gets data from the comment property to update, but not backwards.

I would not like to state that the search for a solution is meaningless. I myself wonder how this can be. But I’m pessimistic.

Maybe, this is the most reliable syntax for the Finder (that is, avoid using AppleScript alias or other non-Finder file specifications directly):

set hfs to (choose file) as text
tell application "Finder" to tell file hfs to set comment to "Test2"

It’s not applescript but you could use Automator to set the comments. In years past, I too had problems in getting applescript to reliably set finder comments but for whatever reason, it now works for me in a handful of scripts that I use regularly.

But at the time, I used Automator because I found it worked reliably and I could easily change the comment. When I need to add comments to many folders I leave the workflow open and change the text to insert as needed. Basically, with command-V, command-R, I can modify the selected files.

But as you didn’t mention how you plan to set the text, I thought about just using the clipboard so I created a workflow with the following actions:

Application receives files and folders as input

Get Contents of Clipboard
Set Value of Variable [Variable: Text]
Get Selected Finder Items
Set Spotlight Comments for Finder Items [Text]

The ‘Text’ in the last action is the previously defined variable. I have ‘ignore this action’s input’ checked on the ‘Get Contents of Clipboard’ action.

If you don’t want to go have to switch to Automator and type Command-R each use, then try this: Save as an Application and drag it onto the Dock. To use, click the Dock icon. Quick and dirty but it works well. Hope this helps.