frankster5000
frankster5000

Reputation: 11

Is it possible to use the alert Finder provides when moving a file to a directory where a file with that name exists in my own app?

I'm building a mac-app for people to organise files. One of the things I allow people to do is to move or copy files to specific directories from within my app. I use FileManagers 'moveItem(at:to:)' or 'copyItem(atPath:toPath:)' to do so, which also allows me to catch errors. Based on these errors, I can of course create custom alerts for specific edge cases.

However, since Finder already provides alerts for such occasions, I was wondering if I could prompt Finders default alerts instead of having to re-create them.

I'm especially interested in the alert shown when multiple files already exist at the location the user tries to move/copy files to and Finder allows to 'Keep both', 'Stop' or 'Replace' these files. Because this alert also includes a 'Apply to all'-checkbox unusual place for a custom NSAlert.

Thanks!

Upvotes: 0

Views: 80

Answers (1)

Parag Bafna
Parag Bafna

Reputation: 22930

You can use apple script to move file.

tell application "Finder"
    move POSIX file "/Users/xyz/fileName" to POSIX file "/Users/xyz/test"
end tell

This will display finder alert.

Upvotes: 0

Related Questions