putting macbook to sleep at pre-defined time?

Apple hardware/software and related topics.
Forum rules
Any posts concerning pirated software or offering to buy/sell/trade commercial software are subject to removal.
GIJoe
Posts: 874
Joined: Sat Mar 29, 2003 11:44 am
Location: Germany -> UK -> Germany...

putting macbook to sleep at pre-defined time?

Unread postby GIJoe » Tue May 13, 2014 5:36 pm

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.

User avatar
ClassicHasClass
Donor
Donor
Posts: 2072
Joined: Wed Jul 25, 2012 7:12 pm
Location: Sunny So Cal
Contact:

Re: putting macbook to sleep at pre-defined time?

Unread postby ClassicHasClass » Tue May 13, 2014 8:50 pm

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, 175MHz 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 * RDI PrecisionBook * BeBox * Solbourne S3000 * Commodore 128 * many more...

User avatar
bigD
Posts: 466
Joined: Tue Jun 17, 2008 8:38 pm
Location: Philadelphia

Re: putting macbook to sleep at pre-defined time?

Unread postby bigD » Tue May 13, 2014 8:57 pm

Have you tried the 'Schedule' option in the Energy Saver module of System Preferences?
:Onyx2: :Indigo2: :O3x0:

User avatar
vishnu
Donor
Donor
Posts: 3174
Joined: Sun Mar 18, 2007 3:25 pm
Location: Minneapolis, Minnesota USA

Re: putting macbook to sleep at pre-defined time?

Unread postby vishnu » Tue May 13, 2014 11:23 pm

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...

:Tezro: :Octane2:

User avatar
yetanother**ixuser
Donor
Donor
Posts: 491
Joined: Fri May 21, 2004 4:47 am
Location: Flynn's Arcade

Re: putting macbook to sleep at pre-defined time?

Unread postby yetanother**ixuser » Wed May 14, 2014 3:10 am

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

GIJoe
Posts: 874
Joined: Sat Mar 29, 2003 11:44 am
Location: Germany -> UK -> Germany...

Re: putting macbook to sleep at pre-defined time?

Unread postby GIJoe » Wed May 14, 2014 3:52 am

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. :)

User avatar
duck
Donor
Donor
Posts: 729
Joined: Mon Oct 27, 2003 5:22 pm
Location: Jakobstad, Finland
Contact:

Re: putting macbook to sleep at pre-defined time?

Unread postby duck » Wed May 14, 2014 4:22 am

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, octane 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.

User avatar
guardian452
Donor
Donor
Posts: 3429
Joined: Tue Aug 21, 2007 10:12 pm
Location: United States
Contact:

Re: putting macbook to sleep at pre-defined time?

Unread postby guardian452 » Wed May 14, 2014 4:29 am

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]

User avatar
hamei
Posts: 10433
Joined: Tue Feb 24, 2004 4:10 pm
Location: over the rainbow

Re: putting macbook to sleep at pre-defined time?

Unread postby hamei » Wed May 14, 2014 8:12 am

duck wrote:Running things once at a specific time is the job of 'at'.

Ooh. Useful. Thank you !
I spent a fortune on booze, birds, and fast cars ... the rest I just squandered

robespierre
Posts: 1552
Joined: Mon Sep 12, 2011 2:28 pm
Location: Boston

Re: putting macbook to sleep at pre-defined time?

Unread postby robespierre » Wed May 14, 2014 8:13 am

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:

User avatar
duck
Donor
Donor
Posts: 729
Joined: Mon Oct 27, 2003 5:22 pm
Location: Jakobstad, Finland
Contact:

Re: putting macbook to sleep at pre-defined time?

Unread postby duck » Thu May 15, 2014 12:59 am

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, octane 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.


Return to “Apple”

Who is online

Users browsing this forum: No registered users and 2 guests