AppleScript to rename files
Another AppleScript problem that was vexing me this morning. Again, you would think that this would be easy… I wanted to rename a file to append the name of the enclosing folder onto it.
For example, the file “Testfile.txt” inside a folder called “Folderstuff” would be renamed to “Folderstuff Testfile.txt.” Here’s the (drawn out) AppleScript code:
(* Renames the selected file to append the enclosing folder name to the front. *) tell application "Finder" activate set theFile to selection as text set TheName to name of (theFile as alias) set SourceFolder to name of (folder of the front window as alias) set NewName to (SourceFolder & " " & TheName) set name of file theFile to NewName end tell
I know it’s faster to do this with a shell script, but I want to keep it in AS for now.
June 12th, 2008 at 5:26 pm
I’ve since updated this script to work with multiple files