In my app, I like to have the OSX Finder copy a file or folder.
(Note: I have good reasons for using the Finder instead of using shell cmds, NSWorkspace or other means, so there's no need for suggestions in that direction.)
I am currently relying on Applescript for asking the Finder to perform the copy operation. Here's a sample script for testing:
tell application "Finder"
try
copy file POSIX file "/etc/bashrc" to folder POSIX file "/private/tmp"
-- alternative with same behavior:
--duplicate POSIX file "/etc/bashrc" to POSIX file "/private/tmp"
on error errmesg number errn
display dialog "Error thrown: " & errmesg
end try
end tell
Now the problem is this: If the destination item already exists, the script throws an error and cancels the copy operation.
However, I would rather have the Finder display the "item exists" dialog that it shows when doing such a copy operation in the Finder interactively, like this one:
Now, here's the thing: If I run this script from the 3rd party app Script Debugger, then this dialog appears!
So, obviously there is a way to get the Finder to display the dialog instead of throwing an exception. But how? Who knows the secret to this?
Well, for my own needs I've found a solution: Instead of using an AppleScript, I need to use the AppleEvents API directly.
There, I can supply the values kAEAlwaysInteract | kAECanSwitchLayer
to AESend
's SendMode parameter. This makes the dialogs appear in the Finder (and also bring the Finder to front in this case).
For someone relying on AppleScript, though, this is not a solution, unfortunately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With