Quit and reboot best practices?

Hi all,

What are the best practices for forcing the system to reboot after quitting an application? I am creating a customized installer for a client that requires a reboot at the end. The installer has a GUI and uses an authenticated shell script (sudo password has previously been entered) to do most of the heavy lifting.

Thanks in advance for any thoughts. Sorry if this topic has been previously discussed. I haven’t managed to find a search term that pulls me up results I am looking for from the forum.

This is what I use in On Site Backup after a backup to sleep or shutdown or restart:

dim ae as appleevent ae=newappleEvent("FNDR","rest","MACS") if not ae.send then msgBox "The computer couldn't be restarted." end if

Thanks David. Sorry for the slow reply… just finding my way around the new forum and didn’t have my notifications set up yet.

Hm… I tried out an appleevent like that and it didn’t seem to work. I’ll check my code and see if I can get this running.

I have code for Log Out, Quit App (obviously!), Restart, Shutdown and Sleep for Mac and Windows (the technique usually varies between platforms).

Nice! Any way I can beg/borrow/steal that from you? :slight_smile:

In one app I’m using the restart method below, to restart the App.

As I want to handle a restarted app differently, I pass the string “imRESTART” as args. Then in app.Open I test for args like this:

If Instr(System.CommandLine,"imRESTART")>0 Then …

My restart method:

[code]Sub restart()
Dim n As Integer
n = MsgBox(app.kAppName + " will restart now.", 0)

If n = 1 Then //user pressed OK

#If TargetCocoa
  
  Dim s As New Shell
  Dim p2 As String = App.ExecutableFile.Parent.Parent.Parent.ShellPath.ReplaceAll("\","")
  Dim cmd As String = "open -n '" + p2 + "' --args imRESTART"
  
  // Now Restart the app
  s.Execute(cmd)
 App.imQuit  // Cleanup and then Quit
  
#EndIf

#If TargetWin32 OR TargetLinux
  App.ExecutableFile.Launch
  App.imQuit
#EndIf

Elseif n = 7 Then
//user pressed No
End If
End Sub
[/code]

This is what I have at the end of On Site Backup based a popup menu:

'the user may choose to perform a particular function on completion 'For Windows System commands go to www.monkeybreadsoftware.net/system-system-method.shtml select case AfterBackup.Text case "Do Nothing" 'do nothing! case "Log Off", "Log Out" #if TargetMacOS then script = "tell application ""System Events"" " + EndOfLine + "log out" + EndOfLine + "end tell" + EndOfLine tempShell.execute "/usr/bin/osascript -e'" + script + "'" #elseif TargetWin32 then tempBoolean = ExitWindowsMBS(0) #endif case "Quit App" quitAfterBackup = True case "Restart" #if TargetMacOS then script = "tell application ""System Events"" " + EndOfLine + "restart" + EndOfLine + "end tell" + EndOfLine tempShell.execute "/usr/bin/osascript -e'" + script + "'" #elseif TargetWin32 then tempBoolean = ExitWindowsMBS(2) #endif case "Shutdown" #if TargetMacOS then script = "tell application ""System Events"" " + EndOfLine + "shut down" + EndOfLine + "end tell" + EndOfLine tempShell.execute "/usr/bin/osascript -e'" + script + "'" #elseif TargetWin32 then tempBoolean = ExitWindowsMBS(1) #endif case "Sleep" #if TargetMacOS then script = "tell application ""System Events"" " + EndOfLine + "sleep" + EndOfLine + "end tell" + EndOfLine tempShell.execute "/usr/bin/osascript -e'" + script + "'" #endif end select end if

David, thanks. Sorry to be so long in getting back to you. I was away on vacation for a few weeks, but managed to get off a working solution to the client before leaving using your osascript approach. Appreciate it!