I’m new to AppleScript, and have been writing a script to prepend the current date to an existing file or folder name. The script appears to work well, except for a very specific instance. When using the script to rename a single text file (i.e. a file with the ‘.txt’ extension) on Mac OS Sonoma 14.5, Finder hangs with spinning beachball, requiring a relaunch. The file in question remains unchanged i.e. the script does not completely execute.
Running the script does not trigger the same issue under these conditions:
Are any of you able to replicate the problem? Any idea what’s going on?
Running the script does not trigger the same issue under these conditions:
- Using more than one .txt file i.e. it works fine when two or more .txt files are selected in Finder.
- Using multiple files or a mix of files and folders, with a single .txt file in the selection.
- Using files of types other than .txt (e.g. .jpg, .pdf, .workflow, etc.), single or otherwise.
- On a folder with ‘.txt’ added to the end of the folder name.
- On a file of a different type e.g. .jpg that has had its extension changed to .txt (with corresponding warning from Finder about changing file extensions).
- On Mac OS Ventura 13.6.7 i.e. no problem at all, even with single .txt files. I haven’t tested on other versions of Mac OS.
AppleScript:
activate application "Finder"
set prependText to "xyz "
tell application "Finder"
set theSelection to the selection
repeat with anItem in theSelection
set currentName to name of anItem
set newName to prependText & currentName
set name of anItem to newName
end repeat
end tell
Are any of you able to replicate the problem? Any idea what’s going on?