spotlight comment from text item

this is another approach to solving my previous post. the following script get me close, but i’m missing something to get the returned text item entered as a spotlight comment for the file.


set {ASTID, text item delimiters} to {text item delimiters, ":"}

tell application "Finder"
	set theFile to selection
end tell
set filePath to theFile as Unicode text
set fileName to -3th text item of filePath

set text item delimiters to {"."}

set newComment to -2th text item of fileName

tell application "Finder"
	set comment of theFile to newComment
end tell

if i change the set newComment to simply “say” the -2th text item, it does say the right words, so i am correctly singling out wheat i want. i just want it to go into the spotlight comment field.

Here’s two ways to get the complete chain of containers down to the selection from the HD.

-- using containers
tell application "Finder"
	set theFile to selection as alias
	set N to name of theFile
	set Pth to {theFile}
	set tNames to {N}
	repeat
		try
			set end of Pth to container of last item of Pth
			set end of tNames to name of last item of Pth
		on error
			exit repeat
		end try
	end repeat
end tell
set tNames to items 2 thru -1 of reverse of tNames

--  Using text item delimiters -- much quicker, just parse the file path
tell application "Finder" to set tFile to selection as alias as Unicode text
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theFolders to text items of tFile
set AppleScript's text item delimiters to ASTID
items 2 thru -1 of reverse of theFolders

See this Code Exchange item by Bruce Phillips for setting or getting Spotlight comments.

Awesome. Thanks much. I haven’t tried it yet, but it looks like what was missing for me was setting the path as an alias was key…