Here is a checklist to follow if you want maximum battery life -- for instance if you're about to get on a long plane flight.
- quit all programs except those you'll be running.
- spot-check the system logs with
Console
. - spot-check filesystem access with
fs_usage
. (This will be fairly distressing if you haven't run through the process below.)
Hopefully things are peaceful and predictable.
Restart the computer -- this gives you good overhead on occupied system memory and means the machine is in a prepared state.
After restart:
-
From the menu bar, turn off:
- airport
- bluetooth
- drop box
- time machine
-
From System Preferences,
- Security: disable remote receiver
- Time Machine: Off
- Keyboard: illumination off
-
Pay off disk access now:
- Launch all the programs you think you'll be running,
- open the documents you'll probably be editing (and close the ones you won't)
-
However, don't get so exuberant that things start swapping -- this will ferociously consume your battery. The 'System Memory' tab in Activity Monitor should show a big healthy chunk of green; try to keep it that way.
-
Set screen brightness to minimum
-
pause indexing on launchbar / quicksilver / whatever
-
Use
gfxCardStatus
to ensure you're on the 'integrated' card -
Disable crashplan (if you use it) and the helpd indexing daemon:
sudo launchctl unload /System/Library/LaunchAgents/com.apple.helpd.plist sudo launchctl unload /Library/LaunchDaemons/com.crashplan.engine.plist
-
Browser:
- Safari in my experience is WAY quieter than Chrome.
- but if you're in chrome, visit about:memory and close any offending tasks
- If you're in chrome, and just going to be reading / browsing documentation etc, you could consider killing the Shockwave plugin -- but some page functionality might die with it.
- Do not disable Spotlight indexing unless you're sure nothing you use will depend on it. You absolutely don't want to spend your flight trying to persuade
mds
not to re-index your disk.
The following shows how to find the things that can sap your battery life -- cascading disk access, auto-launched apps that are crashing, and so forth.
You're fucking with Deep Magick here, and I'm not around to help, so exercise bold prudence.
Put your program in a peaceful state -- quit your programs, disable wi-fi, etc. Shut down everything that you can think of that would be doing anything.
-
open console, look for log messages -- make sure nothing is bouncing repeated errors
- if it's a thing that's failing to launch, you can try
sudo launchctl unload [file]
. If that stops the log bombardment, you've found your problem
- if it's a thing that's failing to launch, you can try
-
These property list files or directories collectively enumerate what the computer will run. If something is raising a ruckus, it is almost certainly one of these that's launching it. You can view any
.plist
file with the Property List Editor (found in XCode) or by runningplutil -convert xml1 -o - [file]
:~/Library/Preferences/com.apple.loginitems.plist ~/Library/Preferences/com.apple.systemuiserver.plist /System/Library/LaunchDaemons/ /System/Library/LaunchAgents/ /Library/LaunchDaemons/ /Library/LaunchAgents/ ~/Library/LaunchAgents/
In terminal, give yourself a large-but-finite scrollback buffer (say, 50,000 lines) and run sudo fs_usage -w -f filesys
. This will show a line on every single filesystem call. It's a lot.
If you also name a process, fs_usage
will only report its actions. For instance, sudo fs_usage -w -f filesys mdworker
will show what things are triggering the spotlight indexer to run.
With nothing running, on my computer I only see the following:
- occasional calls to
usbmuxd
. I think this is looking for my iPhone. - periodic updates to
~/Library/Preferences/com.apple.loginitems.plist
. This is annoying and I haven't been able to get it to stop. cron
waking up and doing nothing (unless it is one of its special times, in which case you'll want to play angry birds until the compputer is quiet again).launchd
syncing to diskfseventsd
sounding the everything is OK alarm.mDNSReporter
sounding for servers and bonjour devices (I think).
The filesystem by default tracks access times. This means every time a file is read, there is at some point a write to disk to update its filesystem metadata. Here's how to disable it:
Create a file called /Library/LaunchDaemons/com.infochimps.noatime.plist
(if you like, put your own vanity in the filename and the file's Label field) containing:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.infochimps.noatime</string> <key>ProgramArguments</key> <array> <string>mount</string> <string>-vuwo</string> <string>noatime</string> <string>/</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
After the restart, mount
should show the disk has been mounted noatime
:
worblehat ~$ mount
/dev/disk0s2 on / (hfs, local, journaled, noatime) # <--- Hooray!
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
Some programs update their savedState file every time there is any activity. Not Cool. One such culprit is Terminal
.
Here's how to prevent the constant modification of that file. The process is similar with other programs, but I wouldn't worry about it unless the saved state file is both large and frequently modified (as Terminal's is). In the process, this makes it so Terminal starts with the same window+tab layout every time -- I actually like it that way, you may feel differently.
- set up your terminal windows how you'd always like to remember them (that is, what you'd like to see when you start the program). Use
⌘k
(clear scrollback)⌘⌥R
(hard reset) in each tab to have it show no prior lines. - visit
~/Library/Saved Application State
, and copy thecom.apple.Terminal.savedState
directory somewhere else. - disable constant updates of the Saved Application State file:
defaults write com.apple.Terminal NSQuitAlwaysKeepsWindows -bool false
- quit Terminal.
- freeze the Saved State information:
- move the savedState directory back to
~/Library/Saved Application State
- hit
⌘I
('Get Info'), click the padlock in the bottom right of the inspector pane, and authenticate - check 'locked'
- move the savedState directory back to
- relaunch terminal. It should appear with the same layout you set up.
fs_usage
should no longer show writes to the file. However, you will see lines in the console log complaining about it being locked. I'm pretty sure this is the right tradeoff.
There are some files that receive regular constant updating the whole time key programs are in use. You don't want these updates to then trigger the Spotlight indexing daemon (mdworker
).
Navigate to System Preferences > Spotlight Panel > Privacy Tab. Then add the following directories to spotlight's exclusion list, by clicking the '+' button, then pressing ⇧⌘G
and typing in the path:
~/Library/Caches
and/Library/Caches
~/Library/Logs
,/Library/Logs
and/var/log
~/Library/Preferences
~/Library/Saved Application State
Check the size of your Spotlight index:
sudo du -mc /.Spotlight-V100
Mine weighs in at 1224 MB, which is about as big as you should let it get. If you would like to see all the files indexed, run
sudo true ; sudo mdfind / > /tmp/spotlight_all-`date +%Y%m%d`.log &
This will run for many minutes. To see where most of the files are hiding, run
cat /foo/spotlight_all-`datename`.log | cut -d/ -f1-5 | sort | uniq -c | sort -n | tail -n 1000
Here are some things that contribute disproportianately:
/Developer/Platforms
~/.rbenv
~/.rvm
/Applications/iWeb.app
/Applications/GarageBand.app
and/Library/Application Support/Garageband
/Library/Printers
Turn off "Calculate All Sizes" and "Show Icon Preview" on folders you visit in the Finder. The latter will access the disk just to show you shiny icons but is mostly harmless. The "Calculate All Sizes" can be a killer, though. Make sure it's off by default. To find directories whose view options are non-default (for any reason), run locate .DS_Store
.