Every few months I have a bunch of files to rename. I’m thinking of putting the orignal name, new name in a text file to use as an external array that can be called from Applescript such as
(*
if the file contains return-delimited lines, eahc of which is:
OLDNAME and a tab and NEWNAME
parseChars() is a handler I use a lot to do separate text into lists.
*)
property nameChangeList: "Drive:folder:namechangelist" -- file that holds your name changes
property folderPath: "Drive:folderWithFiles:" -- folder containing files to be renamed
on run
set fileChangeBlock to read alias nameChangeList
set parsedLines to parseChars(fileChangeBlock)
repeat with oneParsedLine in parsedLines
set {oldName, newName} to parseChars(oneParsedLine, tab)
renameFile(folderPath, oldName, newName)
-- where renameFile is your handler that does the renaming
end repeat
end run
on parseChars(thisText, parseString)
-- version 1.2
set oldDelims to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to the {parseString as string}
set the parsedList to every text item of thisText
set AppleScript's text item delimiters to oldDelims
return parsedList
on error errMsg number errNum
try
set AppleScript's text item delimiters to oldDelims
end try
error "ERROR: parseChars() handler: " & errMsg number errNum
end try
end parseChars