I want to run a bash script on my jailbroken iPhone whenever it is being charged. Currently my script looks like this:


ACpower=$(pmset -g | sed -n '2 p' | grep -o '*')
if [ "$ACpower" != "*" ]; then
    exit 0

rest of script...

As you can see I'm using the pmset package to basically output a list of different variables and then extract the * which indicates if it is being charged or not. If it is not being charged the script stops, otherwise it continues with the rest of it.

Next I was thinking of adding this to a launchdaemon to basically run this script at a given interval.

However, that also gives rise to my question for you guys: If I run this command say every 15 or 30 seconds will that have a noticeable impact on my battery life? Or is there a better way to monitor this variable change than letting the script be ran at an interval?


Actually you don't need to write it at all! Use Activator! You can add an activator event that runs whenever you start charging or stop charging.

Also there is Activator plugin that allows you to run a shell script on an Activator event.


I don't have any of my jailbroken devices with me currently, but I can get you the name of the Activator plugin.

  • Thank you! This was a much simpler solution, works fine on my iPhone. – nStgmk Nov 8 '14 at 8:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .