Real Software Forums

Restart mac programatically (not AppleScript) ?
Page 1 of 1

Author:  jay4365 [ Sat Jan 12, 2013 6:14 am ]
Post subject:  Restart mac programatically (not AppleScript) ?

Does anyone know a way to programatically restart a mac other than using Apple Script?

I've been looking into Apple Events, the code below seems to 'send' ok but nothing happens:

A = New AppleEvent("aevt", "rest", "")
If A.Send Then
MsgBox "Bah hum bug."
End If

..I tried variations:
AppleEvent("aevt", "rest", "")
AppleEvent("FNDR", "rest", "")
AppleEvent("FNDR", "rest", "")

(using latest RB Pro, ML 10.8.2, iMac 2.66GHz 4 GB RAM, xCode and tools installed)

Author:  Goofie [ Sat Jan 12, 2013 9:41 am ]
Post subject:  Re: Restart mac programatically (not AppleScript) ?

If you don't want to use AppleScript, you have alternatives...

(1) take a look at the Shell class to give the appropriate unix command...
It should be easy to attach the following code to a button...
Dim s As Shell
s = New Shell
s.Execute("the command i want to execute")
For the right command look at e.g.

(2) You can also explore the launchd-daemon, in combination with Lingon, then you even don't need to use RealBasic :wink:

Author:  ktekinay [ Sat Jan 12, 2013 1:25 pm ]
Post subject:  Re: Restart mac programatically (not AppleScript) ?

This will work too:
dim sh as new Shell
sh.Execute "osascript -e 'tell app ""System Events"" to restart'"

Or you can create a standalone AppleScript with that command and include it in your project.

Author:  jay4365 [ Mon Jan 14, 2013 11:24 am ]
Post subject:  Re: Restart mac programatically (not AppleScript) ?

Thanks both of you, I'll use the shell method for now.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group