Shut Down Mac Automatically For Bedtime

As the most achievement-driven female on the earth, every once in a while, I find myself slipping into staying up late working on my Mac (watching YouTube blink-blink).

I’m looking at you, Mac

This is intolerable because:

And more importantly,

I’m certain that the root cause is the plummeting of my judgment and self-regulation at midnight.

So, here is my plan.

I need to set myself up so I cannot act stupidly when my brain is in “stupid mode.” This is the only way to reserve a bit of foresight and help that next-morning self get work done.

Before macOS 13.0, you can schedule your Mac to shut down through the schedule tab in the battery panel. Here is what you have in macOS 12 (Monterey). Idk what’s wrong with this UI, but Mac people decided to remove it in macOS 13 (Ventura)

Now, only one option left.

An excuse for something?

Coding! 🫦 🤪

  1. pmset is the power manager in Mac.

  2. You can schedule something periodically using repeat or one-time using schedule

  3. Monday to Sunday is MTWRFSU. This is the way to set “everyday”.

  4. You can restart, shutdown, poweron , and some others that you probably don’t want to touch.

  5. You can check out your current schedule using pmset -g sched

  6. You can cancel your schedule by selecting their index integer sudo pmset repeat cancel 0or call cancel all of them without a number: sudo pmset repeat cancel

  7. You can see settings made by both you and your system using pmset -g

  8. Of course, you can read the manual man pmset

sudo pmset repeat restart F 21:30:00
sudo pmset repeat shutdown MTWRSU 21:30:00
pmset -g sched
    Repeating power events:
      shutdown at 9:30PM Some days
    Scheduled power events:
      [0]  wake at 01/10/2023 16:56:05 by 'com.apple.alarm.user-visible-com.apple.CalendarNotification.EKTravelEngine.periodicRefreshTimer'
      [1]  wake at 01/11/2023 10:40:36 by 'com.apple.alarm.user-visible-com.apple.acmd.alarm'
sudo pmset repeat cancel
sudo pmset repeat cancel 0
sudo pmset schedule restart "10/31/22 09:00:00"
pmset -g
    System-wide power settings:
    Currently in use:
       lidwake              1
       lowpowermode         0
       standbydelayhigh     86400
       proximitywake        1
       standby              1
       standbydelaylow      10800
       ttyskeepawake        1
       hibernatemode        3
       powernap             1
       gpuswitch            2
       hibernatefile        /var/vm/sleepimage
       highstandbythreshold 50
       displaysleep         10
       womp                 1
       networkoversleep     0
       sleep                1 (sleep prevented by useractivityd, sharingd)
       acwake               0
       halfdim              1
       tcpkeepalive         1
       disksleep            10
man pmset

This seemed to be working until…. bedtime came, and my Mac asked me

😶 (╯°□°)╯︵ ┻━┻

OK, I need it to forcefully shut down the computer without asking me…let’s use a cron job…

  1. Type sudo crontab -e in terminal

  2. A vim editor will pop up. Type in your schedule, for example, 30 21 * * * /sbin/shutdown -h now to shut down at 9:30 every day. Here are examples of writing correct cron expressions.

sudo crontab -e
0 21 * * * /sbin/shutdown -h now

Now it shuts down without asking me…….

Now, I’m happy

Other habits to improve my bedtime consistency:

  1. No eating after 7 pm, so I won’t have a hard time falling asleep because of my stomach.

  2. Phone lock after 9 pm.

  3. Schedule boring tasks for working hours at night to wane down my brain. (This one doesn’t quite work, because when that brain is excited, no task is boring….yeah, that brain, because I don’t have full ownership.)

OK.

That’s all about me and my life. Mechanic but exciting.