Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Linux Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Linux/Linux Sudo
This example is the version from Tue, 23th May 2016.
Project "Linux Sudo.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control iMessage Inherits TextField
ControlInstance iMessage Inherits TextField
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control iAlert Inherits TextField
ControlInstance iAlert Inherits TextField
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control iCommand Inherits TextField
ControlInstance iCommand Inherits TextField
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control iUser Inherits TextField
ControlInstance iUser Inherits TextField
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control iDescription Inherits TextField
ControlInstance iDescription Inherits TextField
End Control
Control RunButton Inherits PushButton
ControlInstance RunButton Inherits PushButton
EventHandler Sub Action()
dim s as new LinuxSuMBS
s.Command = iCommand.Text
s.User = iUser.Text
s.Description = iDescription.Text
s.Message = iMessage.Text
s.Alert = iAlert.Text
call s.ExecuteSudo
tExitCode.Text = str(s.ExitCode)
tLasterror.Text = str(s.LastError)
tLasterrorMessage.Text = s.LastErrorMessage
End EventHandler
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
Control tLasterror Inherits Label
ControlInstance tLasterror Inherits Label
End Control
Control tLasterrorMessage Inherits Label
ControlInstance tLasterrorMessage Inherits Label
End Control
Control Label8 Inherits Label
ControlInstance Label8 Inherits Label
End Control
Control tExitCode Inherits Label
ControlInstance tExitCode Inherits Label
End Control
EventHandler Sub Open()
dim f as FolderItem = FindFile("testScript")
dim b as BinaryStream = BinaryStream.Create(f, true)
b.Write "#!/bin/bash"
b.Write EndOfLine.UNIX
b.Write EndOfLine.UNIX
b.Write "myuser=$(whoami)"
b.Write EndOfLine.UNIX
b.Write "mydate=$(date)"
b.Write EndOfLine.UNIX
b.Write EndOfLine.UNIX
b.Write "zenity --info --text ""$myuser $mydate"""
b.Write EndOfLine.UNIX
b.Close
f.Permissions = &o755
#if RBVersion < 2013 then
iCommand.Text = f.UnixpathMBS
#else
iCommand.Text = f.NativePath
#endif
End EventHandler
Function FindFile(name as string) As FolderItem
// Look for file in parent folders from executable on
dim parent as FolderItem = app.ExecutableFile.Parent
while parent<>Nil
dim file as FolderItem = parent.Child(name)
if file<>Nil and file.Exists then
Return file
end if
parent = parent.Parent
wend
End Function
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS Linux Plugin.