AppleScript and macOS10.14 and 10.15 issues

Anyone has some pointers why the below code isn’t working (while it should).
This removes a file named test.png on the desktop to the trash/bin. The code below is basically an example code from MBS.
My guess is that the NSAppleScriptMBS.DeterminePermissionToAutomateTarget isn’t doing what it should and does not give the permission.

[code]
Dim CodeLines() as string
CodeLines.Append “on Add(Name1)”
CodeLines.Append " set bestand to POSIX file Name1"
CodeLines.Append " tell application ““Finder”” to delete file bestand"
CodeLines.Append “end Add”

Dim a as new NSAppleScriptMBS(CodeLines)
Dim error as dictionary
Dim CompileOkay As Boolean = a.Compile(error)

if CompileOkay then

Dim ScriptFuncName As String = “Add”
dim bestand as string = SpecialFolder.Desktop.child(“test.png”).ShellPath
bestand = ConvertEncoding(bestand, Encodings.UTF16)

Dim ScriptParams() As NSAppleEventDescriptorMBS
ScriptParams.Append NSAppleEventDescriptorMBS.descriptorWithString(bestand)

Dim p as NSAppleEventDescriptorMBS
p = NSAppleEventDescriptorMBS.descriptorWithBundleIdentifier(“com.apple.Finder”)
dim e as integer = NSAppleScriptMBS.DeterminePermissionToAutomateTarget(p, “", "”, true)
p = a.executeSubroutine(ScriptFuncName, ScriptParams, Error)

if error = nil then
Dim ScriptResult As String = p.stringValue

MsgBox "ScriptResult:" + EndOfLine + EndOfLine + ScriptResult

else
MsgBox “Error running script.” + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorMessage, “Unknown error”) + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorBriefMessage, “Unknown error”) + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorNumber, “Unknown error”)
end if
else
MsgBox “Error loading script.” + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorMessage, “Unknown error”) + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorBriefMessage, “Unknown error”) + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorNumber, “Unknown error”)
end if[/code]

Don’t try to automate the Finder.

Why? Isn’t it allowed anymore?
It does work when using the older AppleScriptMBS. With NSAppleScriptMBS it fails.

dont you require a n entry in the plist for NSAppleEventsUsageDescription
https://developer.apple.com/documentation/bundleresources/information_property_list/nsappleeventsusagedescription

[quote=441595:@Norman Palardy]dont you require a n entry in the plist for NSAppleEventsUsageDescription
https://developer.apple.com/documentation/bundleresources/information_property_list/nsappleeventsusagedescription[/quote]

Yes, although I did not mentioned this earlier, I already added this plist entry. It keeps popping “Not authorized to send Apple events to Finder.” Errorcode -1743

Note: it does work when I use the AppleScriptMBS (but this will not work anymore with macOS10.15). So I need to use NSAppleScript from now on.
The Applescript code is the same for both - that’s not the issue.

Forgotten to add: I also added the compiled app to the System Preferences > Security & Privacy > Privacy > Automation.

And it still does not work.

Have you code signed the application?

With the App Sandbox, while it was technically possible, Apple said at the time that scripting Finder, System Preferences and System Events would not be allowed. Maybe they followed through with the newer API.

You can also try OSAScript via a shell.

IMHO, I don’t expect scripting to survive much longer. Apple Script is not used on iOS and it seems to be going against their current ‘security’ mindset.

boxing everything off from each other might be secure but geezus it sure kills functionality

The app was codesigned (with hardened option).
My guess is indeed that macOS 10.15 refuses to use Apple Script with the Finder etc…

Bummer… that may be the end of one my apps.
Agh well…

I suspect (and I am not the ony one) that Apple is slowly deprecating AppleScript in macOS…

Is there’s an entry for AppleScript in the macOS Catalina Release Notes ?

I always believed that apps that touched finder or system events with AppleScript were not allowed in the MAS.