That AppleScript way worked just fine at it’s time.
It still works. But requires quite some overhead (AppleEvents usage description, codesign entitlements), and is no longer a good user experience (“the .app wants to automate your system. allow? yes/no”).
Up until macOS 10.13 (or even 10.14.4/5) that’s been fine - for our needs.
Right - an edge case. As a user I might even be happy if Finder gets re-started
Anyway… This is how I move files/directories/an-old.app to Trash on macOS nowadays:
NSFileManager trashItemAtURL:resultingItemURL:error:
[code]//These Declares require macOS 10.8+ (Xojo 2017.03 builds for OS X 10.9+)
Declare Function trashItemAtURL Lib “Cocoa” selector “trashItemAtURL:resultingItemURL:error:” ( NSFileManagerInstance As Integer, inUrl As Integer, outUrl As Integer, outError As Integer ) As Boolean
Declare Function defaultManager Lib “Cocoa” selector “defaultManager” ( NSFileManagerClass As Integer ) As Integer
Declare Function NSClassFromString Lib “Cocoa” (className As CFStringRef) As Integer
Declare Function NSerrorlocalizedDescription Lib “Cocoa” selector “localizedDescription” (NSErrorInstance As Integer) As CFStringRef
Declare Function NSURLfileURLWithPathIsDirectory Lib “Cocoa” selector “fileURLWithPath:isDirectory:” (NSURLClass As Integer, path As CFStringRef, directory As Boolean) As Integer
Dim newLocation, NSError As Integer
Dim bSuccess As Boolean = trashItemAtURL( defaultManager( NSClassFromString( “NSFileManager” ) ), NSURLFileURLWithPathIsDirectory( NSClassFromString( “NSURL” ), poFolderitem.NativePath, poFolderitem.Directory ), newLocation, NSError )
If (bSuccess = False) Then
Dim sErrorMessage As String = NSErrorlocalizedDescription( NSError )
//cope with it
end if[/code]