I have situations where I need to duplicate a file and slightly modify the name of the new file. Let’s say I have a file selected in a Finder window named 123MainBWHT.jpg. The BW in the name stands for “Black & White”. I’m writing a script that I can attach to a QuicKey. When I run the script, it would duplicate the file to the same folder but rename it 123Main4cHT.jpg (4c for “Four Color”). Here’s what I have so far, but it gets hung up when I try to rename the duplicated file:
property colorList : {{"BWHT.jpg", "4cHT.jpg"}, {"4cHT.jpg", "BWHT.jpg"}, {"BWHTM.jpg", "4cHTM.jpg"}, {"4cHTM.jpg", "BWHTM.jpg"}, {"DDN4c.jpg", "DDNBW.jpg"}, {"DDNBW.jpg", "DDN4c.jpg"}}
tell application "Finder"
	set ProcessList to selection
	repeat with i from 1 to (count of ProcessList)
		set theItem to (item i of ProcessList) as string
		set currName to theItem
		
		repeat with thisItem in colorList
			if theItem ends with the first item of thisItem then
				set nameChange to second item of thisItem
				set CurrCount to count currName
				set endCount to count characters of nameChange as string
				set minusEnd to CurrCount - endCount
				set shortName to (text 1 thru minusEnd) of currName
				set newName to shortName & nameChange
				duplicate theItem as alias
				set duplicateItem to shortName & " copy.jpg"
				set name of file duplicateItem to newName
			end if
			
		end repeat
	end repeat
end tell
Can anyone offer a fix or a work around? Is there a shell script that could solve this problem?
Thanks - slimjim5811