Here is the Automator Quick Action for changing the duplicated filename from filename copy.ext to filename ST.ext. It is written to handle multiple duplications (singly) where filename copy 4.ext will be changed to filename ST.ext. It will produce an Alert dialog and quit if you attempt to use the Quick Action on a non-duplicated file. I have tested this on macOS 11.5.2 on an M1 mini.
Launch the Automator application, either from your /Applications folder or from the Dock > Launchpad > Other folder. It will present a chooser dialog where you click New Document, then Quick Action, and then the choose button.
You will be presented with a Library column on the left from which to drag and drop actions in order into the larger right-hand workflow window. For this Quick Action, select Library > Utilities > Run AppleScript and drag/drop it onto the workflow window. Remove that boilerplate content, and then copy/paste the following code into the Run AppleScript window.
use framework "Foundation"
use AppleScript version "2.4" # Yosemite or later
use scripting additions
property NSString : a reference to current application's NSString
property FindStr : "copy"
property ReplaceStr : "ST"
on run {input, parameters}
tell application "Finder"
# only process the currently selected file in the Finder
if selection is {} then return
set afile to selection as alias
set str to name of afile
try
# return either the word copy, or if multiple duplicates, then copy n=2..n
set copyStr to (do shell script "egrep -io '(copy|copy \\d)' <<<" & str's quoted form)
on error
display alert "You have attempted to change a non-duplicated file — quitting." as critical giving up after 15
return
end try
if length of copyStr = 1 then
# we have a first duplicate with just the word copy in the name
set name of afile to my string_replacement(str, FindStr, ReplaceStr)
else
# it is a 2nd or more duplicate selected so copyStr is "copy n"
set name of afile to my string_replacement(str, copyStr, ReplaceStr)
end if
end tell
return
end run
on string_replacement(astr, FindStr, repStr)
# string replacement solution
return ((NSString's stringWithString:astr)'s stringByReplacingOccurrencesOfString:FindStr withString:repStr) as text
end string_replacement
Click the hammer icon on the Run AppleScript toolbar. Next, at the top of the Automator window, you will set the Workflow receives current files or folders in Finder. Then you can then save the Quick Action with. your name choice. Mine was called Replace Duplicate Copy String. This needs to fit on a rather narrow menu, so be thoughtful with the name string. Once you have saved it, it will be stored in /Users/username/Library/Services, and you can edit it simply by launching Automator again, ignoring the chooser panel, and just select the Quick Action by name from Automator's Recent Items menu.
Right-click and duplicate a file. With the duplicate selected, right-click on it, and from the secondary menu, choose Quick Actions and a Quick Action sub-menu will appear. Choose the name you gave your Quick Action and watch the duplicated name change.
Here is what the Quick Action workflow should look like in Automator: