I often (for example on the train) want to put my macbook into a state that will maximise the amount of time I have before the battery runs out – so far example I'll switch off the bluetooth, then switch off the wifi, then alter the brightness – my question is, can I do all of this from the command line? Then I run some nice little script…
Macbook – low power from the command line
command linepower
Related Question
- Mac – Time Machine progress from the command line
- Taking care of your Mac (put into a sleep or shutting down)
- MacBook – Power Line Adapter (PLA) network reducing Macbook Pro’s battery life
- MacBook: Force hibernation, even on AC power (not battery power)
- Mac – Force “low power mode” on mac
- IOS – Keep low power mode on all the time
- IPhone 7 Plus takes days to turn on showing Apple logo or black screen
- MacOS – Finding MacBook power status from command line (AC plugged in, or not)
Best Answer
You can, but you will need some extra utilities:
brightness - you can download the program at http://dev.sabi.net/svn/dev/trunk/LocationDo/brightness.c and compile it using the command:
gcc -std=c99 -o brightness brightness.c -framework IOKit -framework ApplicationServices
Or you can just download it from my server at http://attic.luo.ma/brightness.bz2
Once you have it,
brightness 0.01
will lower the brightness as much as possibleBluetooth - The command you want is
blueutil
which you can find here https://github.com/toy/blueutil. I have a compiled version of that available at http://attic.luo.ma/blueutil2.bz2. I also have another, older version of a program by the same name which you can download from http://attic.luo.ma/blueutil.bz2.Whichever program you use, the
-h
flag will explain how to use it.Wi-Fi - You can turn AirPort power on or off using:
networksetup -setairportpower <device name> <on off>
where
<device name>
is probably either en0 or en1You can find out which it is using
networksetup -listnetworkserviceorder | egrep "Wi-Fi, Device"
For my MacBook Air (which uses en0), the command to turn it off is:
networksetup -setairportpower en0 off
More Settings
Be sure that you have changed the Energy Settings in System Preferences too, but you can also set them using:
sudo pmset -b sleep 10
to tell the computer to sleep after 10 minutes when on battery, and/or:
sudo pmset -b displaysleep 5
to tell the computer display to sleep after 5 minutes, when on battery (the -b flag indicates battery).
pmset -g
will show you your current settings.