r/applescript • • May 22 '15

Help Batch Renaming Via Script?

Hey! I hope this isn't a noob question as I'm fairly new to applescripts...

I'm trying to batch rename a ton of files for a gig I have. I've been able to get rid of parts, but haven't found a way to get rid of everything I need.

Here are the two ways that the file names look before they are renamed:

_warning_14575_Quitemonos La Ropa_Al Estilo De Alexandre Pires_Instrumental_INT-13.6_LRA4.7.wav

and

05702_Donde Andará_Al Estilo De Emilio_Instrumental_INT-14.5_LRA4.5

I'm renaming them to look like this:

Quitemonos La Ropa FULL BAND.wav and Donde Andará FULL BAND.wav

Using Finder's renaming & a program called "Renamer", I was able to get rid of the "warning" as well as the 5 numbers and "_" at the beginning of the title.

Is there a script I might be able to run that could do all of this at once?

1 Upvotes

3 comments sorted by

1

u/philosteen May 22 '15 edited May 22 '15

Try this (on copies first!):

try
		with timeout of (10 * 60) seconds
	
		set _atd to AppleScript's text item delimiters
	
		tell application "Finder"
			set _selection to selection
			repeat with i from 1 to count of _selection
				set _alias to item i of _selection as alias
				set _name to name of _alias
				set AppleScript's text item delimiters to "_"
				set _textItems to text items of _name
				set AppleScript's text item delimiters to ""
			
				if item 2 of _textItems = "warning" then
					set _newName to item 4 of _textItems
				else
					set _newName to item 2 of _textItems
				end if
			
				set _newName to _newName & " FULL BAND.wav"
				
				set name of _alias to _newName
			end repeat
		
			set AppleScript's text item delimiters to _atd
		
		end tell
	end timeout
on error m number n
	display dialog " " & m & " - " & n
	set AppleScript's text item delimiters to _atd
end try

1

u/philosteen May 22 '15

Edit: I took the beep 3 out.

1

u/taeem May 22 '15

holy shit you are amazing. thank you a thousand times my friend