The conversation on this page has been archived and is no longer active.

script to force sleep?

Message #1 - Posted 2005/08/28 - Carl Witthoft

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

The reason I ask is that, while my mac will sleep if I select Sleep from a menu or from the login screen, the EnergySaver / PowerManagement system utterly fails to put the machine to sleep after I log out, regardless of the delay times or other settings.

thanks
Carl

Message #2 - Posted 2005/08/28 - Troubled Tony

Carl Witthoft wrote:

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

The reason I ask is that, while my mac will sleep if I select Sleep from a menu or from the login screen, the EnergySaver / PowerManagement system utterly fails to put the machine to sleep after I log out, regardless of the delay times or other settings.

Try playing around with pmset, and even see if you can figure out the problem.

Message #3 - Posted 2005/08/28 - Tom Stiller

Previously, Carl Witthoft wrote:

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

Have a look at "LoginWindow Manager", available via VersionTracker. This utility will allow you to set a script to run at login a/o logout time.

Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3
7BDA 71ED 6496 99C0 C7CF

Message #4 - Posted 2005/08/28 - Carl Witthoft

Previously, Troubled Tony wrote:

Carl Witthoft wrote:

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

The reason I ask is that, while my mac will sleep if I select Sleep from a menu or from the login screen, the EnergySaver / PowerManagement system utterly fails to put the machine to sleep after I log out, regardless of the delay times or other settings.

Try playing around with pmset, and even see if you can figure out the problem.

I've done that. Problem is that no matter what settings I choose (from the Preferences GUI or from pmset on the command line), the computer won't go to sleep on its own.

Message #5 - Posted 2005/08/28 - Carl Witthoft

Previously, Tom Stiller wrote:

Previously, Carl Witthoft wrote:

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

Have a look at "LoginWindow Manager", available via VersionTracker. This utility will allow you to set a script to run at login a/o logout time.

That looks like a great tool.

So, now all I need is the actual name of the shell command that will sleep the computer. (as opposed to pmset, which just sets parameters for whatever does the sleep actions).

Carl

Message #6 - Posted 2005/08/28 - Tom Stiller

Previously, Carl Witthoft wrote:

Previously, Tom Stiller wrote:

Previously, Carl Witthoft wrote:

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

Have a look at "LoginWindow Manager", available via VersionTracker. This utility will allow you to set a script to run at login a/o logout time.

That looks like a great tool.

So, now all I need is the actual name of the shell command that will sleep the computer. (as opposed to pmset, which just sets parameters for whatever does the sleep actions).

The shell command "osascript" will run an AppleScript and the AppleScript statement 'Tell application "Finder" to sleep' will put the computer to sleep. Putting them together is a straightforward task and a worthwhile learning experience.

Tom Stiller

PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3
7BDA 71ED 6496 99C0 C7CF

Message #7 - Posted 2005/08/29 - Daniel Cohen

Carl Witthoft wrote:

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

Why do you want to do this?

I'm wondering if another approach will do what you need conveniently. For instance, if the idea is that nobody could get into your computer by just waking it up (because you had been logged out and they would need to log in) you could just set the machine to require a password on wake from sleep.

If I haven't guessed your reason correctly, it could still be true that understanding why you want to do this would help in providing a different solution.

Send e-mail to the Reply-To address;
mail to the From address is never read

Message #8 - Posted 2005/08/29 - Carl Witthoft

Previously, Tom Stiller wrote:

Previously, Carl Witthoft wrote:

Previously, Tom Stiller wrote:

Previously, Carl Witthoft wrote:

OK,
I thought of another possible way to get my silly iMac to sleep after I log out.
Maybe there's some way to run a script at logout time (or start up a cron job?) that will make the darn Sleep function work?

Have a look at "LoginWindow Manager", available via VersionTracker. This utility will allow you to set a script to run at login a/o logout time.

That looks like a great tool.

So, now all I need is the actual name of the shell command that will sleep the computer. (as opposed to pmset, which just sets parameters for whatever does the sleep actions).

The shell command "osascript" will run an AppleScript and the AppleScript statement 'Tell application "Finder" to sleep' will put the computer to sleep. Putting them together is a straightforward task and a worthwhile learning experience.

Thanks, Tom. That's exactly what I needed (osascript).

Of course, perversity has attacked :-) Turns out that, at least for every account other than mine, my computer is sleeping just fine. I have to go track down the offending APE or PrefPane or daemon, I guess.

And to answer someone else's question: I want to have my Mac put itself to sleep after logging out just to save energy and alleged wear&tear. It's just one of those anal-compulsive quirks that I'd like the machine to do what it's supposed to (as opposed to my manually clicking the "sleep" button on the Login screen).

Carl

Message #9 - Posted 2005/08/30 - Peter Renzland

In On 2005-08-29 Carl Witthoft <carl@witthoft.com> wrote:

Of course, perversity has attacked :-) Turns out that, at least for every account other than mine, my computer is sleeping just fine. I have to go track down the offending APE or PrefPane or daemon, I guess.

I've made a little shell script that takes care of the real problem in a proper way. :-) I offer it here to the world. I've packaged it in a loop so it can just be run. Others may want to use cron instead of the while loop (and take away the voices :).

#!/bin/sh
# Sandman -- Peter Renzland, Planix.Ca, 2005
# (sandman sends covert progress reports :-)

CHECKINTERVAL=${1-60}
while :
do

set -- $(pmset -g | grep sleep)
SLEEPLIMIT=$2

IDLESECONDS=$((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ \ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000)) (( IDLEMINUTES= $IDLESECONDS / 60 ))

if (( $IDLEMINUTES > $SLEEPLIMIT ))
then
say "Yo! Computer has been idle for $IDLEMINUTES minutes. It should have gone to sleep after $SLEEPLIMIT. Sweet Dreams!"

osascript -e 'Tell application "Finder" to sleep' sleep 15.sandman.waking_up # wait till it comes to

IDLESECONDS=$((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ \ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000)) if (( $IDLESECONDS > 15 ))
then
say "Computer is waking up. Doo something now or remain idle!" sleep 10.sandman.do_something.$IDLESECONDS:$IDLEMINUTES
fi

fi

sleep $CHECKINTERVAL.sandman:$IDLESECONDS.secs:$IDLEMINUTES.mins done

## Peter -- send mail to Planix dot ca -- I don't read Sympatico mail

Message #10 - Posted 2005/08/30 - Sandman

Previously, Peter Renzland wrote:

In On 2005-08-29 Carl Witthoft <carl@witthoft.com> wrote:

Of course, perversity has attacked :-) Turns out that, at least for every account other than mine, my computer is sleeping just fine. I have to go track down the offending APE or PrefPane or daemon, I guess.

I've made a little shell script that takes care of the real problem in a proper way. :-) I offer it here to the world. I've packaged it in a loop so it can just be run. Others may want to use cron instead of the while loop (and take away the voices :).

#!/bin/sh
# Sandman -- Peter Renzland, Planix.Ca, 2005
# (sandman sends covert progress reports :-)

CHECKINTERVAL=${1-60}
while :
do

set -- $(pmset -g | grep sleep)
SLEEPLIMIT=$2

IDLESECONDS=$((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ \ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000)) (( IDLEMINUTES= $IDLESECONDS / 60 ))

if (( $IDLEMINUTES > $SLEEPLIMIT ))
then
say "Yo! Computer has been idle for $IDLEMINUTES minutes. It should have gone to sleep after $SLEEPLIMIT. Sweet Dreams!"

osascript -e 'Tell application "Finder" to sleep' sleep 15.sandman.waking_up # wait till it comes to

IDLESECONDS=$((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ \ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000)) if (( $IDLESECONDS > 15 ))
then
say "Computer is waking up. Doo something now or remain idle!" sleep 10.sandman.do_something.$IDLESECONDS:$IDLEMINUTES
fi

fi

sleep $CHECKINTERVAL.sandman:$IDLESECONDS.secs:$IDLEMINUTES.mins done

## Peter -- send mail to Planix dot ca -- I don't read Sympatico mail

Heeeey, don't use my nick in the thread title :-D

I claim ownership pf this script :-D

Sandman[.net]

Message #11 - Posted 2005/08/31 - Troubled Tony

Peter Renzland wrote:

sleep 15.sandman.waking_up # wait till it comes to
sleep 10.sandman.do_something.$IDLESECONDS:$IDLEMINUTES sleep $CHECKINTERVAL.sandman:$IDLESECONDS.secs:$IDLEMINUTES.mins

What? Is this some idiosyncratic syntax for when running with a shell trace?

Need Help? Have a Question?

Looking for more help, comments, and answers?

Ask your questions on Ask Different. Ask Different is a community of Apple users ready to help.