Hello
I am currently working on an AppleScript to automate the process of renaming multiple files in Finder; but I’m running into an issue where the script doesn’t seem to apply the intended renaming pattern across all selected files.
The script works for a single file; but when multiple files are selected, it only renames the first one and stops without affecting the others. I would appreciate guidance on how to loop through all selected files and ensure that the renaming process applies to all of them.
I’m using the following AppleScript to rename files:
tell application “Finder”
set selectedFiles to selection
repeat with aFile in selectedFiles
set theName to name of aFile
set name of aFile to “NewName_” & theName
end repeat
end tell
The script works well when renaming a single file; but when selecting multiple files, only the first file gets renamed. Could this be related to how the script handles the selection? I’m not sure if I need to adjust the selection handling or the way the script interacts with the Finder to loop through all files correctly. Checked macos - Creating a batch file-renaming script for use in OSX Automator - Stack Overflow and Okta administrator documentation guide for reference .
Any advice would be much appreciated!
Thank you !