script to force sleep?

I thought of another possible way to get my silly iMac to sleep after I log out.
Carl Witthoft wrote on :

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

Troubled Tony replied on :

Carl Witthoft carl@redacted.invalid 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.

Tom Stiller replied on :

In article carl-6C1531.12481328082005@redacted.invalid, Carl Witthoft carl@redacted.invalid 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.

Carl Witthoft replied on :

In article 87ednZPDWLmmYIzeRVn-uw@redacted.invalid, Troubled Tony tt@redacted.invalid wrote:

Carl Witthoft carl@redacted.invalid 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.

Carl Witthoft replied on :

In article tomstiller-AE142F.14253128082005@redacted.invalid, Tom Stiller tomstiller@redacted.invalid wrote:

In article carl-6C1531.12481328082005@redacted.invalid, Carl Witthoft carl@redacted.invalid 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

Tom Stiller replied on :

In article carl-4273CD.16575828082005@redacted.invalid, Carl Witthoft carl@redacted.invalid wrote:

In article tomstiller-AE142F.14253128082005@redacted.invalid, Tom Stiller tomstiller@redacted.invalid wrote:

In article carl-6C1531.12481328082005@redacted.invalid, Carl Witthoft carl@redacted.invalid 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.

Daniel Cohen replied on :

Carl Witthoft carl@redacted.invalid 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.

Carl Witthoft replied on :

In article tomstiller-778C45.17502828082005@redacted.invalid, Tom Stiller tomstiller@redacted.invalid wrote:

In article carl-4273CD.16575828082005@redacted.invalid, Carl Witthoft carl@redacted.invalid wrote:

In article tomstiller-AE142F.14253128082005@redacted.invalid, Tom Stiller tomstiller@redacted.invalid wrote:

In article carl-6C1531.12481328082005@redacted.invalid, Carl Witthoft carl@redacted.invalid 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

Peter Renzland replied on :

In carl-62D45C.18360029082005@redacted.invalid On 2005-08-29 Carl Witthoft carl@redacted.invalid 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
Sandman replied on :

In article JsPQe.2557$884.342866@redacted.invalid, Peter Renzland phr040919@redacted.invalid wrote:

In carl-62D45C.18360029082005@redacted.invalid On 2005-08-29 Carl Witthoft carl@redacted.invalid 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

Troubled Tony replied on :

Peter Renzland phr040919@redacted.invalid 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?