Mac Finder native copy dialog

I meet one requirement

  1. copy files into a a folder,
  2. Require same behavior as Mac drag file action, such as pop up “Copy” dialog asking confirm if there is a same name file in the target folder…

Applescript has copy command of “Finder”,

tell application "Finder"
copy file "file.." to folder "folder.."
end try
end tell

This code can only meet my 1) requirement, but not the 2) requirement. So could anybody tell the solution for me?


the proper Finder command to move files is move, not copy
and duplicate to copy files.
The requested confirm behavior can be forced with replacing ask

tell application "Finder"
	move file "file.." to folder "folder.." replacing ask
end tell

Note: don’t use try blocks while testing scripts. You will never get any helpful error message, if something goes wrong

Thanks for your help.

But follow your request, I meet below error message in the terminal,

My code is:

tell application "Finder"
move file " *:*:*:a.txt" to folder "*:*:*:a:" replacing ask
end tell

Is there anything wrong in my script?

And there no confirm dialog pop up.
Actually, I hope Finder can pop up “confirm” dialog in this case.

just omit “replacing ask”. Paradoxically then the Finder asks

I can’t get the Finder to ask.
“replacing yes” or “with replacing” replaces the file without asking.
“replacing no” or “without replacing” leads to an error message about the file already existing.
“replacing ask” leads to the same error message.
Omitting the replacing stuff also leads to that error message.

“Replacing” of the command “move” is boolean, according to the AppleScript Dictionary. Boolean means it can be either true or false. Could it be that the “ask” value is not even supported in this case?
In cases where “ask” is supported, the dictionary says “ask/no/yes” instead of “boolean”, like in the command “close” (in Pages or AppleScript Editor, for example) where “saving” can be “ask/no/yes”.

Not here. I.e. not when I run my script from within Script Editor or as a standalone .app, built on 10.6.8.
HOWEVER: If I run the same script in Script Debugger, then I get the Finder to ask about replacing the existing item.

I’ve posted the same question today on SO, here:
It includes an example.

This is still a mystery.

Stefan, if you get the dialog, would you please describe your testing environment and show the script you’re using? Unless you’re testing in SD - then it’s no wonder it works (well, it’s still unclear why it works in SD).

That’s the case. If you want a dialog, you need to use “without replacing”, trap for an error, put up your own dialog, and proceed accordingly.

Shane, please read the posting I made on StackOverflow.

What you’re suggesting is a work-around, but not the only option, as one can see if one tries this in Script Debugger, which achieves to get the dialog from the Finder, just as the original poster asked for. And StefanK’s reponse suggests as well that there’s some way to get the Finder to show the dialog just as if one had initiated the copy/move directly in the Finder.

I’m not sure why SD 4.5 is doing it that way, but I’d classify it as a bug. I understand it results in the behaviour preferred, but IMO exploiting bugs usually backfires at some stage. The dictionary is explicit: “replacing” is a boolean parameter.

I’m not sure where the replace ask form comes from, maybe it was an option in a former AppleScript version.

Regardless of the real existing problem your code on stackoverflow contains the wrong command copy instead of move.

Indeed I’m using ScriptDebugger, so everything behaves exactly as you described.

As a solution/workaround you could catch the error and display your own warning dialog.
Then the behavior in ScriptDebugger / Script Editor is (almost) the same

set sourceFile to "disk:path:to:file.ext"
tell application "Finder"
		move file sourceFile to desktop
	on error errorMessage number errorNumber
		if errorNumber = -15267 then
			display dialog "An item named \"file.ext\" alreeady exists in this location. Do you want to replace it with the one you're moving" buttons {"Stop", "Replace"} cancel button "Stop" with icon caution
			move file sourceFile to desktop replacing yes
			display dialog errorMessage & " (" & errorNumber & ")"
		end if
	end try
end tell


You confirm that you see the same effect in SD, so when you wrote a while back that you get the Finder’s dialog, you were probably also testing this in SD, right? However, if you managed to get the Finder’s dialog outside of running the script in SD, that would be the interesting part this thread would like to explore more.

The question remains: SD does something that leads to the effect to have the Finder handle the conflict, and I want to find out how to archieve that. (Note: I am actually using this script, or AppleEvents, in my own larger app, so this script is just an example, not the solution). Working around by showing my own dialog is just not the same, and so I keep pressing to find out how SD does it.

I’m working only with SD, for my own stand alone projects I’m always using the shell or even Objective-C for file management.

I guess only Late Night Software can answer the question

I’ve received a reply from Mark Alldritt at Latenight Software.

He knew of this “issue” and investigated it a while ago. He could not figure out the details of this behavior, though.

The only lead is that SD is using its own OSA Component.

Now, where do I find a skeleton OSA Component to try this myself? :wink: