Real Software Forums
http://forums.realsoftware.com/

Restart mac programatically (not AppleScript) ?
http://forums.realsoftware.com/viewtopic.php?f=7&t=46534
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", "com.apple.systemevents")
If A.Send Then
//
Else
MsgBox "Bah hum bug."
End If

..I tried variations:
AppleEvent("aevt", "rest", "com.apple.finder")
AppleEvent("FNDR", "rest", "com.apple.finder")
AppleEvent("FNDR", "rest", "com.apple.systemevents")

(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 developer.apple.com e.g. http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/shutdown.8.html

(2) You can also explore the launchd-daemon, in combination with Lingon http://www.peterborgapps.com/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
http://www.phpbb.com/