Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 10, 2012, 12:33 AM   #1
m021478
macrumors 6502
 
Join Date: Nov 2007
Rename Finder items using Spotlight Comments Metadata

Trying to figure out how to use Automator to batch rename a bunch of Finder items using the metadata in the spotlight comments of my files to rename said files.

Any suggestions would be greatly appreciated... Thanks!
__________________
Please don't tell me to "search the forums" before posting. I can assure you that I already have!
m021478 is offline   0 Reply With Quote
Old Apr 10, 2012, 12:35 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Try this

The script works with files not with an alias. The thingy with the little black arrow on it. I included a tumbnail how it looks like. The script runs slow. I have not tested it with a lot of files. The automator action runs faster. All your spotlight comments need to be unique. I you have put in a comment like Tahiti for all your holiday pictures from your last trip to Tahiti it won't work.

Code:
set this_folder to (choose folder with prompt "Pick the folder containing the files to process:") as string
tell application "System Events"
	set these_files to every file of folder this_folder
end tell
repeat with i from 1 to the count of these_files
	set this_file to (item i of these_files as alias)
	set this_info to info for this_file
	if visible of this_info is true and alias of this_info is false then
		-- insert actions here for: this_file
		tell application "Finder"
			get properties of this_file
			set file_name to name of this_file
			set file_name_extension to name extension of this_file
			try
				set file_comment to comment of this_file
				if file_comment is not "" then
					set name of this_file to file_comment & "." & file_name_extension
				end if
			on error errMsg number errNum
				display dialog errMsg & " " & errNum giving up after 5
			end try
		end tell
	end if
end repeat
Automator :

Get Specified Finder Items --> A folder not files
Get Folder Contents
Run Applescript with this code inside it :
Code:
on run {input, parameters}
	(* Your script goes here *)
	repeat with i from 1 to the count of input
		set this_file to (item i of input as alias)
		set this_info to info for this_file
		if visible of this_info is true and alias of this_info is false then
			-- insert actions here for: this_file
			tell application "Finder"
				get properties of this_file
				set file_name to name of this_file
				set file_name_extension to name extension of this_file
			try
				set file_comment to comment of this_file
				if file_comment is not "" then
					set name of this_file to file_comment & "." & file_name_extension
				end if
			on error errMsg number errNum
				display dialog errMsg & " " & errNum giving up after 5
			end try
			end tell
		end if
	end repeat
	--	return input
end run
Attached Thumbnails
Click image for larger version

Name:	Afbeelding 5.png
Views:	11
Size:	51.3 KB
ID:	335143  
Attached Images
   

Last edited by kryten2; Apr 10, 2012 at 01:26 PM. Reason: Added error handling and leave files with no comment alone
kryten2 is offline   1 Reply With Quote
Old Apr 17, 2012, 11:24 PM   #3
m021478
Thread Starter
macrumors 6502
 
Join Date: Nov 2007
Thanks so much for your help.

How can I use the script you provided to create an automator service to allow me to right-click directly on the files I'd like to rename (not a folder containing the files), and then choose the option to "rename selected files using spotlight comment?

Thanks!
__________________
Please don't tell me to "search the forums" before posting. I can assure you that I already have!
m021478 is offline   0 Reply With Quote
Old Apr 17, 2012, 11:57 PM   #4
m021478
Thread Starter
macrumors 6502
 
Join Date: Nov 2007
Nevermind... I got it

__________________
Please don't tell me to "search the forums" before posting. I can assure you that I already have!
m021478 is offline   0 Reply With Quote
Old Oct 15, 2012, 02:34 PM   #5
Petroff1
macrumors newbie
 
Join Date: Oct 2012
Adding the comment to the name

This modified code puts the comment after the original name with an _

Code:
on run {input, parameters}
	(* Your script goes here *)
	repeat with i from 1 to the count of input
		set this_file to (item i of input as alias)
		set this_info to info for this_file
		if visible of this_info is true and alias of this_info is false then
			-- insert actions here for: this_file
			tell application "Finder"
				get properties of this_file
				set file_name to name of this_file
				set file_name_extension to name extension of this_file
				set file_length to (count of file_name) - (count of file_name_extension) - 1
				set file_body to text 1 thru file_length of file_name
				try
					set file_comment to comment of this_file
					if file_comment is not "" then
						set name of this_file to file_body & "_" & file_comment & "." & file_name_extension
					end if
				on error errMsg number errNum
					display dialog errMsg & " " & errNum giving up after 5
				end try
			end tell
		end if
	end repeat
	--	return input
end run
Petroff1 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
help with better finder rename (renaming various folders) mrjayviper Mac Applications and Mac App Store 1 Jan 20, 2014 06:13 AM
spotlight v finder macuser231 MacBook Pro 2 Sep 5, 2013 12:41 PM
Finder Tags & xmp metadata HoosPhotog OS X Mavericks (10.9) 0 Jun 25, 2013 01:17 PM
Spotlight comments? shawnperson OS X 10.8 Mountain Lion 4 Apr 30, 2013 07:22 PM
tagging versus spotlight comments - your thoughts? jojoba Mac Applications and Mac App Store 0 Mar 11, 2013 09:45 AM

Forum Jump

All times are GMT -5. The time now is 07:13 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC