Wrapper around pmset schedule
for easy near-term sleep and shutdown time setting.
With macOS Ventura, Apple made the flabbergasting decision to remove the ability to schedule sleeps/shutdowns/restarts with their handy UI as part of their Battery Preferences(?) panel, and instead instructs users to use the Terminal.
I often like to schedule my Mac to shutdown in an hour or so to have some background audio as I go to bed. I don't want to do datetime math as I'm going to bed (or ever, really), and also don't want to have to open up my Terminal, and also don't want to issue a sudo
command and enter my password, and also don't want to have to remember what pmset
is called, and also don't want to have to remember its syntax.
Last night, I opened up my Terminal and issued the command:
sudo pmset schedule shutdown "$(date -v+50M '+%D %T')"
to set-up a shutdown in 50 minutes. It's the user-friendly reliability of Apple that has kept me coming back.
Rather than type out that pile of bullshit seen above, I wrote scheduleoff
as a wrapper around it, simplifying the above call to:
scheduleoff shutdown 50
If you used the old UI that Apple removed, you'll remember that there is actually a 10-minute countdown dialog box that pops up at the scheduled time, giving you the option to cancel or proceed immediately. pmset
, and therefore scheduleoff
, have this same feature.
Well, I've been using pmset
quite often over the last several days, and still can't remember what it's name is. There seems to be a contest to remove as many characters as possible from command line tools, which in the modern world of TAB-completion seems outdated. It's supposed to schedule stuff, so I thought "schedule"-something, and it only handles initiating sleeps and shutdowns, so I thought, "off". I imagine I'll wind up thinking, "It's 'schedule'-something, right?", and type in my Terminal "sch[TAB]", then pause, then "[TAB][TAB]" to see everything that starts with "sch" pop up, then see "scheduleoff", and write "sched[TAB]", and then that'll work (for me).
If you are a Rust user, you can use cargo install scheduleoff
.
Pre-built binaries are available for download in the "builds" folder. I do not have an x86 Mac anymore, so I can't tell if the x86 version actually works.
After downloading,
- Store it in whichever folder you want. It would be easiest to just store it in the folder that your Terminal opens up to by default. You can find this by opening your Terminal and typing
open .
, which will open it in Finder. - Rename the file to your liking. I suggest "scheduleoff".
- You need to change permissions, using
chmod 744 <executable>
in Terminal in the folder containing the file, where<executable>
is whatever you named that file. - To run, type
./<executable> [commands]
in Terminal in the folder containing the file, where<executable>
is whatever you named that file, and see below in Use for commands. - If you try to run it and Apple won't let you, right-click on it in Finder and click "Open".
scheduleoff
s intended use case is one-off shutdown or sleep scheduling in the near-term. So the only options are
scheduleoff shutdown MINUTES
scheduleoff sleep MINUTES
where MINUTES
is some number of minutes, e.g. scheduleoff sleep 90
.
MINUTES
must be greater than 0, because if it is 0, then your scheduled time will be missed by pmset
because it will have already passed by.
For any other aspect that the old scheduling UI could handle, you'll have to find some other tool, or use pmset
. For information on how to use pmset
, I recommend this tutorial.
You have two options:
- Wait for the 10-minute countdown dialog.
- Use
pmset
For option 2, see the above linked tutorial, but you'll be writing something like: sudo pmset schedule cancel shutdown "03/13/2023 15:27:41"
.
You'll still have to type in your password to use scheduleoff
, because it uses sudo
. If you think that's annoying, then there are (at least) two options:
- Configure it so that you can use Touch ID for
sudo
. - Make it so that
sudo pmset
doesn't require a password.
I opted for option 2. Below is a description of what I did, though I suggest you read other resources to get comfortable with the process, because bad things will happen if you make a mistake.
It amounted to customizing a sudo
-related file with the added line:
swpease ALL = (root) NOPASSWD: /usr/bin/pmset
Where you would replace "swpease" with your user name. If you're unsure, use whoami
in your Terminal. I suppose you could also verify that pmset
is in the same location with which pmset
.
To add this line to the file you're supposed to add it to, use sudo visudo
, which will enter you into a vim
editor of the file (you should know how to use vim
before you start). It is EXTREMELY IMPORTANT not to make a mistake with this. From the visudo
documentation:
visudo parses the sudoers file after editing and will not save the changes if there is a syntax error. Upon finding an error, visudo will print a message stating the line number(s) where the error occurred and the user will receive the “What now?” prompt. At this point the user may enter ‘e’ to re-edit the sudoers file, ‘x’ to exit without saving the changes, or ‘Q’ to quit and save changes. The ‘Q’ option should be used with extreme caution because if visudo believes there to be a syntax error, so will sudo and no one will be able to run sudo again until the error is fixed. If ‘e’ is typed to edit the sudoers file after a syntax error has been detected, the cursor will be placed on the line where the error occurred (if the editor supports this feature).