Copy File Name to Finder Comment

I have a large audio database that I want to make searchable by finder comment.

Is there an easy way to copy all the file names to the finder comments?

Thanks,

Brian

Brian:

I am curious as to why you’d want to do this since the name is already present in the metadata for the files.

Jim

I use the database cataloging function in Protools. You can have separate clip names and file names in the catalog. The clip name is editable, but the filename is not. I can automatically copy the file comment to the clip name, but I cannot copy the file name to the clip name. I am want to have a more detailed clip name than is in the filename. The easiest way to do this is to import the clip name from the file comment.

All of my CD and audio libraries have short file names, but descriptive file comment. However, the thousands of files that I have recorded only have a short descriptive file name. I just want to be able to copt that file name into the file comment.

I started doing it manually, but that is mind-numbing work.

I could make a script to do some copying in Protools, but if I ever need to re-catalog the files, I will just have to do it all over again.

Thanks,

Brian

I am working on setting the finder comments with another script I have. It seems to do the first part fine, but when it goes to update the Finder Comment it returns the message:

Can set <> of . . .

Suggestions?


on open dropped_items
	set commented to "Testing"
	
	repeat with this_item in dropped_items
		set this_POSIX to POSIX path of this_item
		
		if (this_POSIX ends with "/") then
			
			-- If this item's a folder, get the POSIX paths of all the visible files in it.
			set these_POSICES to paragraphs of (do shell script "find -f " & (quoted form of text 1 thru -2 of this_POSIX) & " \\( -type f -and -not -path '*/.*' \\)")
			
			-- Deal with each file individually.
			repeat with this_POSIX in these_POSICES
				finderCommenter(this_POSIX, commented)
			end repeat
			
		else -- This dropped item's a file.
			finderCommenter(this_POSIX, commented)
		end if
		
	end repeat
	display dialog "Complete"
end open

on finderCommenter(path_to_file, add_this_text)
	tell application "Finder"
		
		--write updated comments
		set comment of path_to_file to add_this_text
		
	end tell
end finderCommenter

The script is passing POSIX path strings to the subroutine.
Finder cannot deal with those, they must be converted to HFS file paths first. Here’s an incantation that works:

tell application "Finder"
	set path_to_file to path_to_file as POSIX file as alias -- coerce text to POSIX file path to AppleScript alias
end tell

The terminology add_this_text suggests it adds the text to what’s already there. It does not. It replaces what is there.

After a little searching I found a much shorter way to do this. It won’t process sub-folders, but it does remove the extension when it copies than name to the comment.

on open dropped_items
	tell application "Finder"
		repeat with each_file in dropped_items
			set extension hidden of file each_file to true
			set name_file to (displayed name of each_file) as Unicode text
			set comment of (each_file as alias) to name_file
			set extension hidden of file each_file to false
		end repeat
	end tell
end open

This should drill down through every folder.

on open dropped_items
	tell application "Finder"
		repeat with each_file in dropped_items
			set_meta(each_file)
		end repeat
	end tell
end open

on set_meta(the_file)
	if folder of the_file is false then
		set extension hidden of file the_file to true
		set name_file to (displayed name of the_file) as Unicode text
		set comment of (the_file as alias) to name_file
		set extension hidden of file the_file to false
	else
		repeat with recursive_file in the_file
			set_meta(recursive_file)
		end repeat
	end if
end set_meta

Thanks, this looks like a clever way of processing sub-folders.

When I run this it just returns the error:

Can’t continue set_meta

It also looks like the command “comment” become a variable when it is in a subroutine.

Ideas?

Thanks,

Brian

Commands in the ‘if’ part are Finder stuff.
Enclose in Finder tell block.

Don’t rush things…