I'm trying to automate running a background application only when my laptop is charging to save battery.
So it will launch when I plug the laptop in, and quit when I take it out.
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityI'm trying to automate running a background application only when my laptop is charging to save battery.
So it will launch when I plug the laptop in, and quit when I take it out.
You can do that very easily using ControlPlane, a free (open-source) application:
ControlPlane, a fork of MarcoPolo, brings context and location sensitive awareness to OS X. With ControlPlane you can intelligently reconfigure your Mac or perform any number of actions based on input from a wide variety of evidence sources [...]
from: https://github.com/dustinrue/ControlPlane
You can very easily add a "power source rule" which then launches or quits an application or script. As you can see in the attached screenshots, it's very easy to set-up.
One option is a third party product like the one discussed here or the free SleepWatcher.
Another option is to write a script to query the status using ioreg
. Here is snipset from code that I found elsewhere sometime ago...
set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable")
tell Cap to set {wallPower} to {last word of paragraph 1}
if wallPower = "Yes" then
....
end if
Have the script to run continuously so you can detect changes and then perform the action you desire as necessary.
Hope that helped.