Keep a Clamshelled Macbook Awake
- read thru pmset man page
https://www.reddit.com/r/MacOS/comments/168wxx8/in_amphetamine_when_always_starting_or_stopping/
/Users/aidangibson/Library/Application Scripts/com.if.Amphetamine/enableDisableSleep.scpt
https://medium.com/macoclock/how-to-prevent-macos-catalina-from-sleeping-when-connected-to-an-external-monitor-e2c876dadaf9
A Macbook will not work in clamshell mode when connected to an external monitor without AC power.
Absolutely disgusting. But what can we do about it?
You can type the following in your shell:
This will keep your Macbook awake, even in clamshell mode, until you disable it by typing:
But typing in those two commands over and over is a tremendous drag. Let’s automate it!
Sudoers
We can’t automate jack shit if we’re constantly being queried for a password every time the command runs. Every time you use sudo
in the Terminal, you are attempting to run a process as “root user” and will be queried for an admin password. Therefore, we are going to selectively nuke that security feature just for pmset and just for your account.
Allow your user to run sudo pmset
with no password auth:
> whoami
to get your username. For me, that’saidangibson
.- (optional)
EDITOR=micro
> sudo visudo -f /etc/sudoers.d/sudoers
create new sudoers fileaidangibson ALL = (root) NOPASSWD: /usr/bin/pmset
Type this in exactly (obviously replacing my username with yours). Fucking up sudoers can absolutely fuck up your computer, which is why we’re not editing the sudoers file directly, instead usingvisudo
.- The general format for this is
<username> ALL = (ALL) NOPASSWD: /path/to/program
. You can also modify this file to allow you to use sudo with no password for all programs. But that’s incredibly stupid and I won’t tell you how to do it.
https://www.digitalocean.com/community/tutorials/how-to-edit-the-sudoers-file
script it to automatically run disablesleep 1 on plugin of hub and disablesleep 0 on unplug of hub
macOS boasts not one but two “automation” softwares. Automator and Shortcuts.
Funnily enough, NEITHER are actually capable of automation!
Alt Method
safer
doesn’t mess w sudoers
wrapper script which uses setuid
caveat of setuid in OSX,
Comments
TODO comments