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]