Apple

putting macbook to sleep at pre-defined time?

hi,

google didn't come up with anything - i'm looking for a method to put my MBP to sleep at some pre-defined time a la 'go to sleep at <this time> on <that date>, no questions asked' .
ideally to be run from terminal and as a normal user, not root.

the background is that i had to disable most of the power management on mine since the automatic GPU-switching when connected to an external monitor on wakeup can lead to a kernel panic (one of the gazillion of documented yet eternally unresolved problems on the apple forums, sadly).

just looking for a way to prevent the machine from running for hours idling where it would normally go to sleep automatically after finishing a job.
cron job that does osascript -e 'tell application "Finder" to sleep'. T,FTFY. :)
smit happens.

:Fuel: bigred , 900MHz R16K, 4GB RAM, V12 DCD, 6.5.30
:Indy: indy , 150MHz R4400SC, 256MB RAM, XL24, 6.5.10
:Indigo2IMP: purplehaze , R10000, Solid IMPACT
probably posted from Image bruce , Quad 2.5GHz PowerPC 970MP, 16GB RAM, Mac OS X 10.4.11
plus IBM POWER6 p520 * Apple Network Server 500 * HP C8000 * BeBox * Solbourne S3000 * Commodore 128 * many more...
Have you tried the 'Schedule' option in the Energy Saver module of System Preferences?
:Onyx2: :Fuel: :Indigo2: :Indigo2IMP: :O3x0:
GIJoe wrote: ...since the automatic GPU-switching when connected to an external monitor on wakeup can lead to a kernel panic (one of the gazillion of documented yet eternally unresolved problems on the apple forums, sadly).

Yet another of the innumerable reasons why my MBP hasn't been turned on in two and a half years. Which isn't to say all you macaholics aren't good people! Wrong, but good... ;)
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...
just in case...

http://gfx.io/

you can also force which graphic card you want to use, so no more switching will occur.
no plan
ClassicHasClass wrote: cron job that does osascript -e 'tell application "Finder" to sleep'. T,FTFY. :)


thanks - that would be the ticket - but how to put in a cron job that only runs once? they also use some unreadable format to set up. not good if you have to google everytime for the syntax beforehand. ;) alternatively, there may be a way to embed it into a shell-script that is fed a variable for date and time and keeps waiting until that condition is met.
or any hack that would enable a normal user to execute 'pmset schedule sleep', really. that one has all the functionality already...

Have you tried the 'Schedule' option in the Energy Saver module of System Preferences?


yes, but it's graphical frontend only. i'm not familiar with automator however... perhaps time to brush up on that?

just in case...
http://gfx.io/
you can also force which graphic card you want to use, so no more switching will occur.


i use that but power-source-based switching has been removed from it - and seems to be the cause.
i just wish there was a way to disable the integrated stuff completely and force the use of the discrete GPU at all times. battery life be damned.

thanks guys, time to have a look at scripting and automator, i think. :)
Running things once at a specific time is the job of 'at'. It might be too oldeyworldey to be fit to exist on such a modern thing as a mac though.
:Octane: halo , oct ane Image knightrider , d i g i t a l AlphaPC164, pond , soekris net6501, misc cool stuff in a rack
N.B.: I tend to talk out of my ass. Do not take it too seriously.
It exists in 10.9... and it works just fine.


Code: Select all

AT(1)                     BSD General Commands Manual                    AT(1)

NAME
at, batch, atq, atrm -- queue, examine, or delete jobs for later execu-
tion

SYNOPSIS
at [-q queue] [-f file] [-mldbv] time
at [-q queue] [-f file] [-mldbv] -t [[CC]YY]MMDDhhmm[.SS]
at -c job [job ...]
at -l [job ...]
at -l -q queue
at -r job [job ...]

atq [-q queue] [-v]

atrm job [job ...]

batch [-q queue] [-f file] [-mv] [time]

DESCRIPTION
The at and batch utilities read commands from standard input or a speci-
fied file.  The commands are executed at a later time, using sh(1).
:

Messi:~ mjw$ at
usage: at [-q x] [-f file] [-m] time
at -c job [job ...]
at [-f file] -t [[CC]YY]MMDDhhmm[.SS]
at -r job [job ...]
at -l -q queuename
at -l [job ...]
atq [-q x] [-v]
atrm job [job ...]
batch [-f file] [-m]
Thinkpad x220 Slack + DWM

Google: Don't Be Evil. Apple: Don't Be Greedy. Microsoft: Don't Be Stupid.
duck wrote: Running things once at a specific time is the job of 'at'.

Ooh. Useful. Thank you !
I never thought that a fat man's face would ever look so sweet ...
You can write a shell script that calls pmset(1) and then "chmod 4755" the script.
something like
#!/bin/sh
pmset schedule sleep "$1 $2"

then "chown root" the script.
:PI: :O2: :Indigo2IMP: :Indigo2IMP:
robespierre wrote: You can write a shell script that calls pmset(1) and then "chmod 4755" the script.
something like
#!/bin/sh
pmset schedule sleep "$1 $2"

then "chown root" the script.


chown before chmod, or the suid bit will be stripped*

*) this possibly does not happen on some platforms
:Octane: halo , oct ane Image knightrider , d i g i t a l AlphaPC164, pond , soekris net6501, misc cool stuff in a rack
N.B.: I tend to talk out of my ass. Do not take it too seriously.