Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to schedule PMSET in a specific way ?

Hi Everyone,


I need to schedule a Mac to start up and shutdown at a certain schedule (mondays, tuesdays,thursdays,fridays Schedule A, wednesdays Schedule B, and weekends Schedule c).

I would like to use the PMSET command but it only allow one pair of events.

Apparently it's possible to make a script to do this. Unfortunately I am quite very new in scripts so I would very much appreciate if someone can help me.


Thanks in advance,


Sebastian

Posted on Apr 19, 2014 6:40 AM

Reply
1 reply

Apr 24, 2014 12:21 AM in response to Sebeyh

It sounds like there are two components to your request, which should make it pretty straightforward.



The first is to craft the various <i>pmset</i> commands for the various schedules.

The second is to apply the appropriate schedule. It's not clear from your post whether you want/expect to do this automatically or you want to manually switch which one is in effect.



The first part is pretty straightforward.



-- setup the various command line options (adjust as necessary)

set scheduleA to "/usr/bin/pmset -a repeat wakeorpoweron MTRF 8:00:00 shutdown MTRF 18:00:00"

set scheduleB to "/usr/bin/pmset -a repeat wakeorpoweron W 9:00:00 shutdown W 20:00:00"

set scheduleC to "/usr/bin/pmset -a repeat wakeorpoweron SU 10:00:00 shudown 22:00:00"


Now you have three variables, one for each schedule.



Next you just need to determine which one to apply. One option is to prompt the user:


-- ask the user which one to apply

set newSchedule to button returned of (display dialog "Which schedule do you want?" buttons {"Schedule A", "Schedule B", "Schedule C"} default button "Schedule A")


Other options may be to look at the current day and determine what the next schedule should be (e.g. if today is Tuesday you know you need to apply Wednesday's schedule, etc.)



Once you know what schedule to apply you can just:


-- interpret the answer

if newSchedule = "Schedule A" then

set theCmd to scheduleA

else if newSchedule = "Schedule B" then

set theCmd to scheduleB

else

set theCmd to scheduleC

end if


-- and do it

do shell scripttheCmd with administrator privileges


Note the above assumes you're using the 'display dialog' approach. You may need to change the script a little if you use some other option.

How to schedule PMSET in a specific way ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.