Crates.io | scheduleoff |
lib.rs | scheduleoff |
version | 0.1.0 |
source | src |
created_at | 2023-03-15 17:23:54.555463 |
updated_at | 2023-03-15 17:23:54.555463 |
description | Wrapper around `pmset schedule` for easy near-term sleep and shutdown time setting. |
homepage | |
repository | https://github.com/swpease/scheduleoff |
max_upload_size | |
id | 810871 |
size | 20,973 |
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.
scheduleoff
DoesRather 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.
scheduleoff
?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).
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:
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"
.
sudo
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:
sudo
.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.
sudo
OverviewIt 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).