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.
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).
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"
try
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
else
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.