Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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...

share|improve this question
1  
Can you provide a more complete list of the things you want to accomplish? You've got Bluetooth, WiFi, and brightness; is there anything else you want to do? –  Nathan Greenstein Feb 12 '12 at 19:33
    
Those are the only things I do at the moment - if someone suggests something else that can be done from the command line that would help save power (I assume one can probably throttle the processor a little as well) then I'm all ears... –  Joe Feb 12 '12 at 19:38
add comment

1 Answer 1

up vote 3 down vote accepted

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 possible

Bluetooth - 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 en1

You 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.

share|improve this answer
    
p.s - the newer version of blueutil can be installed from Homebrew using brew install --HEAD blueutil –  TJ Luoma Feb 12 '12 at 20:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.