-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSystemEventsMod.rbbas
More file actions
96 lines (76 loc) · 2.68 KB
/
SystemEventsMod.rbbas
File metadata and controls
96 lines (76 loc) · 2.68 KB
1
#tag ModuleProtected Module SystemEventsMod #tag Method, Flags = &h1 Protected Function ShutdownOrRestartThisMac(paramRestartOrShutdown as string, byRef paramErrMsg as string, byRef paramErrCodeInt as integer) As Boolean dim mShell as Shell dim mShellResult as string dim mShellErrInt as integer LogToFile(CurrentMethodName + ": ---->") mShell = new Shell mShell.Mode = 0 if ( paramRestartOrShutdown = "" ) then LogToFile(CurrentMethodName + ": ERROR: Received paramRestartOrShutdown is EMPTY.") LogToFile(CurrentMethodName + ": <----") return false end if // Restart: /usr/bin/osascript -e "Tell application \"Finder\" to restart" // Shutdown: /usr/bin/osascript -e "Tell application \"Finder\" to shut down" mShell.Execute("/usr/bin/osascript -e " + Globals.kDoubleQuoteChar _ + "Tell application \" + Globals.kDoubleQuoteChar + "Finder\" + Globals.kDoubleQuoteChar + " to " + paramRestartOrShutdown + Globals.kDoubleQuoteChar) mShellResult = mShell.Result mShellErrInt = mShell.ErrorCode paramErrMsg = mShellResult LogToFile(CurrentMethodName + ": Result of shell command to " + paramRestartOrShutdown + ": '" + mShellResult + "'") LogToFile(CurrentMethodName + ": Shell exit error code = " + str(mShellErrInt) ) if ( mShellErrInt <> 0 ) then LogToFile(CurrentMethodName + ": ERROR: Shell execute failed!") paramErrCodeInt = Globals.kReturnMsgIsError LogToFile(CurrentMethodName + ": <----") return false end if paramErrCodeInt = Globals.kReturnMsgIsSuccess LogToFile(CurrentMethodName + ": <----") return true End Function #tag EndMethod #tag Constant, Name = kRestart, Type = String, Dynamic = False, Default = \"restart", Scope = Protected #tag EndConstant #tag Constant, Name = kShutDown, Type = String, Dynamic = False, Default = \"shut down", Scope = Protected #tag EndConstant #tag ViewBehavior #tag ViewProperty Name="Index" Visible=true Group="ID" InitialValue="-2147483648" InheritedFrom="Object" #tag EndViewProperty #tag ViewProperty Name="Left" Visible=true Group="Position" InitialValue="0" InheritedFrom="Object" #tag EndViewProperty #tag ViewProperty Name="Name" Visible=true Group="ID" InheritedFrom="Object" #tag EndViewProperty #tag ViewProperty Name="Super" Visible=true Group="ID" InheritedFrom="Object" #tag EndViewProperty #tag ViewProperty Name="Top" Visible=true Group="Position" InitialValue="0" InheritedFrom="Object" #tag EndViewProperty #tag EndViewBehaviorEnd Module#tag EndModule