Okay, I made it working exactly as I wanted, so I'd like to inform all people participating here, but also others who might see this while searching for similar content.
The first stumbling block was making sure the application can actually send Apple Events in the first place. And in that regard I admit I should've listened better to @Etresoft and I apologize to him for not listening more carefully and dismissing his remark about "hoops so that the app can actually send Apple Events" too easily. It turned out that, even though the application is NOT sandboxed, com.apple.security.automation.apple-events entitlement is mandatory in the entitlements file. I couldn't assume it would be necessary even for a NON-sandboxed app, but it is.
From my experience with executing AppleScript from another, sandboxed, application I remember that defining com.apple.security.automation.apple-events in the entitlements file and NSAppleEventsUsageDescription in the Info.plist file always go together and that's the case here too. So, if either com.apple.security.automation.apple-events = YES or NSAppleEventsUsageDescription is missing, macOS/TCC won't even prompt you to allow the application to "automate" other application, effectively blocking sending Apple Events (hence, executing Apple Script). The annoying thing about the code above is that it will execute without any error, not giving any clue as for what went wrong.
Once this first hurdle was jumped over, the application started sending Apple Event(s) to Finder, I only needed to figure out how to make it do what I needed.
The following thing was to use -descriptorWithFileURL: when creating AE descriptors for files. Using -descriptorWithString: and passing file's path resulted in the event silently failing.
Finally, the last piece of the puzzle was how to instruct Finder where to copy files. I was struggling to figure out which AEKeyword should be used to pass the destination URL descriptor to the event descriptor. Not passing the destination URL or doing so with the wrong keyword resulted in Finder making file duplicates at the same destination as sources, adding them copy 2, copy 3… in file names, just like making duplicates in Finder's UI. keyAETarget sounded like a logical choice to me, but that turned out to be wrong. Since no other keyword definition seemed logical to me, I had to turn to reverse engineering of AppleScript execution, as per @The Eskimo advice, and figure out what the to parameter of Finder's duplicate command in AppleScript actually translates into in Apple Events. It turned out it translates into the AEKeyword of value 0x696e7368 and using the HFSType constants, that would be 'insh'. It turned out it's defined as keyAEInsertHere. I also took some time to dig into some very old header files in (pre Mac OS X ) MacOS and I found out that constant being defined as keyAETo.
Once this all was put in place, the code above worked fine and behaved exactly as I wanted: in case there were already existing files in the destination, Finder would present its conflict resolution panel. Even passing NSAppleEventSendAlwaysInteract | NSAppleEventSendCanSwitchLayer as options when sending the event wasn't necessary, just passing simple 0 was enough.
I hope this was helpful, I thank you all for help and suggestions you gave while trying to solve this problem.
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags: