Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

low-priority question: duplicating files using the Finder in macOS

Hi,


(low-priority question)


You can duplicate a file in Finder by right-clicking it and choosing Duplicate. Finder creates a duplicate with the word "copy" appended to it.


Can you change the word that Finder appends from "copy" to something else?

Posted on Sep 10, 2021 2:07 PM

Reply
Question marked as Best reply

Posted on Sep 11, 2021 7:13 AM

Apple will not change the Finder behavior, but that doesn't mean one cannot code an Automator Quick Action to allow you to right-click on a file and select a Quick Action to duplicate it, and replace the "copy" string in the duplicated name with another string.


What did you have in mind?

7 replies

Sep 12, 2021 5:39 PM in response to LuigiBenetton

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:


Sep 12, 2021 8:05 AM in response to LuigiBenetton

When you duplicate an original item in the Finder the first time you get filename copy.ext. Without changing that duplicate name, a second duplication results in filename copy 2.ext, and ... filename copy n.ext.


Are you needing filename ST.ext or filename_ST.ext? What about those instances where a generation number appears? Do you want filename ST_n.ext or filename_ST_n.ext, or some variation?


I can code this in Automator for you to shorten your learning curve, but won't be able to get to it until this (9/12) evening, as I am away from home all day with the iPad Pro instead of my Mac.

Sep 12, 2021 4:57 PM in response to LuigiBenetton

I am requesting that the hosts move this post to the Mac OS X Technologies community since coding is involved, and it won't be 20 screens down in the Catalina community by dawn 2021-09-13.


I have a solution working in AppleScript right now that will replace filename copy.ext with filename ST.ext, and if there is more than one duplicate (e.g. filename copy 4.ext, then I check for that and replace copy 4 to appear as filename ST.ext.


Next, I want to build an Automator Quick Action and test how it handles right-clicking on individual files. I should have something by early morning to post here.

low-priority question: duplicating files using the Finder in macOS

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.