HEY!, first post on the forum…well, I have this question about the Sleep command attached to a button that will (of course), put my Mac to sleep. The thing is that it takes sooooo long to put the computer to sleep that I’ve put some text fields in order to show some text while the process is completed. My questions are:
Is it ok that it takes so long to sleep?
On every machine, no matter the processor, speed blah…blah… will always take the same time?
why this takes so long?
The problem is that if in another machine it takes less time, the Mac will go to sleep mode before the text fields are refreshed and when switching to normal mode again, the user will be able to see their content.
works immediately on my machine…Type it in, Hit run, and I’m sleeping right now zzzzzz…
Please note that I did not use a button to acknowledge it, just raw code.
Thanks for the post and please tell us some more – show your script if you don’t mind
nope…I’m not usin’ the “Finder” but the “System Events”…here u go…
(a bunch of code before…)
tell application “System Events”
sleep
end tell
I’m using P.B. but same with Script Editor…it takes up to 30 seconds…mmmmm I wonder why?.. but also if I use the “Finder”…mmmm…whyyyy?..strange, isn’t?
if you don’t care about adding scripting additions (aka OSAX) you can use XTool which has a ‘sleep’ command (that will be renamed, how stupid I am sometimes…) taht put the computer to sleep without requiring to be in the ‘FInder’ (the next release will be this week-end I hope)
OK, I’m newie at Applescript so, not to get confused… to use those scripting additions the end-user of the application would have to have something installed too? Who makes OSAX? (company?)…well, thanks for your time and answering! saludos from Argentina!
Under Mac OS X, “System Events” is the appropriate application to target the ‘sleep’ command. The command only exists in the Finder’s dictionary for compatibility reasons. Hopefully Apple will remove it from the dictionary soon.
As for the delay, it will vary on each machine since it depends on what processes are running at the time. For example, if online via a PPP (dialup) connection, the sleep command will disconnect the PPP link and wait for the phone to hang up before putting the system to sleep.
AFAIK, there is no way to predict how long the sleep will take for any given invocation, even subsequent runs on the same machine.
Just like you can’t predict how long it will take, I also don’t think you can do anything after the sleep command is issued.
Consider the following script:
tell application "System Events" to sleep
beep
When you run it, you system will go to sleep (either instantly, or after a short delay as described above, but you don’t hear the beep, which is the very next command until you wake up.
When you wake, the script continues at the next line and you hear the beep sound.
As a result, i don’t think there’s any way to post a progress dialog or other UI element while the system is preparing for sleep.