Functionality of AppleScript's "Duplicate" command

I’ve got a very simple AppleScript that I use as a service in Finder:


on run {input}
	try
		tell application "Finder" to duplicate input to "/Volumes/named_folder" with replacing
	end try
end run

Using this as a service allows me to right-click on a file in Finder and execute the script on a file or folder. It’s important that this script “duplicates” the file/folder in question - i.e., leaves the original where it is, and places a “copy” of the file in the newly selected location. The script has served me well for several years.

Sometime over the course of the past few months, the functionality of the “duplicate” command seems to have changed. Now my script “moves” the selected file from the original location to the new location - it doesn’t leave a copy of the file in the original location. I can’t find anything online that suggests a change to the “duplicate” command. The dictionary entries for “duplicate” and “move” still appear to be the same as they were before.

I’m looking for a way to modify my AppleScript so that it will leave the original version in place.

Thanks for any suggestions you may have,
John

Model: MacBook Pro 16"
AppleScript: 2.7
Browser: Safari 537.36
Operating System: Other

I think (not sure), the problem is you duplicate input of Automator, which is list of AppleScript aliases. And, the duplicate command of Finder for multiple items is intended for duplicating Finder selection. Logically, to duplicate Automator input you should use repeat loop (duplicate one by one).


on run {input}
	repeat with anAlias in input
		try
			tell application "Finder" to duplicate (contents of anAlias) to "/Volumes/named_folder" with replacing
		end try
	end repeat
end run

Making AppleScript alias list Finder alias list should help as well (not tested):


on run {input}
        -- convert to Finder alias list
	tell application "Finder" to set input to input as alias list
	try
		tell application "Finder" to duplicate input to "/Volumes/named_folder" with replacing
	end try
end run

Maybe, the main problem is you try to duplicate Automator input object (reference to this Automator list) instead of its contents (not tested as well):


on run {input}
	try
		tell application "Finder" to duplicate (contents of input) to "/Volumes/named_folder" with replacing
	end try
end run

@KniazidisR - thank you for your reply. A strange thing happened; when I went to try out your suggestions, I did something to my Automator file that made the original script work again. It must have been “hung up” or something - now it’s working fine.

Most of the time, I have to hunt for the bugs. Sometimes they leave all by themselves - though now I’m really curious about what caused this problem, this time I’m just going to let it be! :confused:

Thanks again,
John

It’s hard for me to say right now if you’ll get strange errors again with your approach. I myself always get the contents of the input into a list variable first, and then work with that list inside tell blocks of applications.