a=new AuthorizationMBS
var fileToBeDeleted(0) as FolderItem
fileToBeDeleted(0) = SpecialFolder.Desktop.Child("test.txt")
dim s(0) as String
s(0)=ConvertEncoding(fileToBeDeleted(0).ShellPath,Encodings.UTF8)
if a.SimpleNewAuthorization then // create
a.Execute("rm",s,true) // and run it
if a.LastError<>0 then
MsgBox "Lasterror on Execute: "+str(a.LastError)
else
a.MakeStreamAsyncron
end if
end if
a=new AuthorizationMBS
dim s(-1) as String
if a.SimpleNewAuthorization then // create
a.Execute("rm " + SpecialFolder.Desktop.Child("test.txt").shellPath,s,true) // and run it
if a.LastError<>0 then
MsgBox "Lasterror on Execute: "+str(a.LastError)
else
a.MakeStreamAsyncron
end if
end if
a.Execute("rm " + fileToBeDeleted(0).ShellPath,s,true)
I haven’t used AuthorizationMBS with shell commands but we have used it to launch auto-update helper apps on macOS successfully for over 10 years.
Here is the code we use (which also supports MS-Windows).
Public Enum AuthoriseAndExecuteResult
OK
Cancelled
TimedOut
Failed
Function AuthoriseAndExecute(pExecutable As FolderItem, pOSXArgs() As String) As AuthoriseAndExecuteResult
Dim tempInteger As Int32
Return AuthoriseAndExecute(pExecutable, pOSXArgs, tempInteger)
End Function
Function AuthoriseAndExecute(pExecutable As FolderItem, pOSXArgs() As String, ByRef pOSErrorCode As Int32) As AuthoriseAndExecuteResult
Dim theResult As AuthoriseAndExecuteResult
Dim osErrorCode As Int32
theResult = AuthoriseAndExecuteResult.Failed
osErrorCode = 0
#If TargetMacOS Then
Dim authorisationObj As AuthorizationMBS
authorisationObj = New AuthorizationMBS
'first attempt to use the unix path to the executable as this should be more reliable than the shell path (needed for osx 10.5 support)
If authorisationObj.SimpleNewAuthorization = True Then
authorisationObj.Execute(pExecutable.UnixpathMBS, pOSXArgs)
'if we received a -60031 error then the executable path could not be found so use the shell path instead
If authorisationObj.LastError = -60031 Then
authorisationObj.Execute(pExecutable.ShellPath, pOSXArgs)
End If
'convert the result into one of our enums
Select Case authorisationObj.LastError
Case 0
theResult = AuthoriseAndExecuteResult.OK
Case -60006
theResult = AuthoriseAndExecuteResult.Cancelled
Case -60005
theResult = AuthoriseAndExecuteResult.TimedOut
End Select
osErrorCode = authorisationObj.LastError
End If
#Else
Const SW_SHOWNORMAL = 1
Const SW_SHOWNA = 8
Dim info As New MemoryBlock(15 * 4)
Dim verb As New MemoryBlock(32)
Dim file As New MemoryBlock(260 * 2)
Soft Declare Function ShellExecuteExW Lib "Shell32" (info As Ptr) As Boolean
Soft Declare Function ShellExecuteExA Lib "Shell32" (info As Ptr) As Boolean
info.Long(0) = info.Size
info.Long(8) = 0
If System.IsFunctionAvailable("ShellExecuteExW", "Shell32") = True Then
verb.WString(0) = "runas"
file.WString(0) = pExecutable.AbsolutePath
Else
verb.CString(0) = "runas"
file.CString(0) = pExecutable.AbsolutePath
End If
info.Ptr(12) = verb
info.Ptr(16) = file
info.Long(28) = SW_SHOWNA
If System.IsFunctionAvailable("ShellExecuteExW", "Shell32") = True Then
If ShellExecuteExW(info) = True Then
theResult = AuthoriseAndExecuteResult.OK
End If
Else
If ShellExecuteExA(info) = True Then
theResult = AuthoriseAndExecuteResult.OK
End If
End If
#EndIf
pOSErrorCode = osErrorCode
Return theResult
End Function
Has your app been given permission to access the desktop? If so, in what way?
Did you ever get the security / access dialog about your app accessing files?
Shell is not a terminal try:
“usr/bin/rm” as the command or lookup the path using “whereis rm” in the terminal, then ise the given path in your xojo shell.