Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 15, 2018 11:50 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Restart mac programatically (not AppleScript) ?
PostPosted: Sat Jan 12, 2013 6:14 am 
Offline

Joined: Tue Dec 18, 2012 7:29 am
Posts: 5
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Restart mac programatically (not AppleScript) ?
PostPosted: Sat Jan 12, 2013 9:41 am 
Offline

Joined: Tue Nov 13, 2007 11:48 am
Posts: 189
Location: Belgium
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:


Top
 Profile  
Reply with quote  
 Post subject: Re: Restart mac programatically (not AppleScript) ?
PostPosted: Sat Jan 12, 2013 1:25 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
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.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: Restart mac programatically (not AppleScript) ?
PostPosted: Mon Jan 14, 2013 11:24 am 
Offline

Joined: Tue Dec 18, 2012 7:29 am
Posts: 5
Thanks both of you, I'll use the shell method for now.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group