You can have your Mac automatically run a command line tool when switching to and from battery power.
We have previously shown how to run an AppleScript when your Mac switches to battery power. This previous recipe was written in AppleScript, but today's recipe will use the new Schedule Assistant task introduced with Power Manager 4.1.
Create a Battery Triggered Command Line Event
- Launch System Preferences and select Power Manager.
- Click Add… to create a new event.
- Choose the template Run a script on battery.
- Click Continue to the Script step.
- Copy and paste your shell script into the Script step:
#!/bin/sh say "Switching to battery power."
- Continue through the remaining steps until your event is created.
After following the above steps, your event is scheduled and ready. Try disconnecting your mains power. A moment after disconnecting, your Mac will speak and warn that you are now running on battery power.