Spencer Watson

Using Activator to handle intermittent events


I use my iPhone every day on my way to work. I plug it into my stereo via USB, and I also connect to the stereo via Bluetooth. The USB has better audio quality, so I use that for playing music. I connect the Bluetooth in case I receive any phone calls, I can use the hands-free calling feature on my stereo. The problem with Bluetooth is that it is a major battery drain. I don't want to leave it running all the time, so I turn it on when I get in my car, and I turn it off when I get out of my car. Sometimes I forget to turn it on, and I end up scrambling if I get a phone call. I wanted this process to be automated.

First, I tried using activator to turn on Bluetooth when power is connected, and turn it off when disconnected. The first action works fine. The second action though, can receive some unintentional triggers. For example, if I plug my phone into my car, then start the car, the power sent to the phone will fluctuate causing the phone to disconnect and reconnect. This would cause the Bluetooth to turn off and back on, causing some delayed pairing and just general funky behavior. So, to fix this problem, I wanted to, somehow, make activator behave as follows: power disconnected event, wait 10 seconds, turn off Bluetooth if power is still disconnected. This way, Bluetooth will only turn off if the power is disconnected for 10 seconds. After some tinkering, I was able to get this to work in practice.

Device Specs:

  • iPhone 5S
  • iOS 8.4
  • Unteathered Jailbreak
  • Activator
  • ActIf
  • iOS Terminal

Steps:

Create the shell script

In order to create my shell script, I needed to have a terminal so that I could search for commands and run tests. I installed iOS Terminal from Cydia for this. By running the command activator listeners, you can get a list of all the activator commands that you can run. I was planning on triggering the ActIf Charging condition, so I found jzplusplus.ActIf.charging in the list of commands, and wrote that down. Activator commands are triggered by calling activator send {{code}}. So, I could test my command so far in the terminal by runningactivator send jzplusplus.ActIf.charging. This will trigger this actIf event, and I will see something happen if I have an event bound to it in Activator.

The other part of my script that I needed was a timeout. sleep {{seconds}} can be used to add a delay in your shell scripts. Commands can be chained together using && So, I can finish my script so that it reads sleep 10 && jzplusplus.ActIf.charging.

Bind the script

Now that I have my script written down, I can run it based on an activator event. I opened activator and navigated to Anywhere -> Power -> Disconnected, since I wanted to trigger my script when the power is disconnected from my phone. In the top right corner, I hit the "More" button. Here, you can create custom actions. The "Run Command" option allows you to run a shell script. So, I create a new "Run Command" action and I title it Actif power delayed. The title can be anything you choose. I think copied my shell script into the Command field, and hit Save. Now, you should see your command listed at the bottom of this Custom Actions screen. Hit Done to go back to the list of actions. Scroll through until you find your action, then tap to select it. Now we have it so that when power is disconnected, it will wait 10 seconds, then call ActIf to check if the phone is charging.

Setup ActIf

Now, I go back to the "Anywhere" page and scroll up to find the "ActIf conditions." Since I am triggering the Charging condition, and I want something to happen if the phone is not charging, I scroll down to select the "Charging condition failed" event. In here, I select the "Deactivate Bluetooth" action.

All Done!

I've done some home tests, but haven't taken it in the car yet. But, when I plug and unplug the phone into my home charger, it seems to work as expected.

Your message has been sent!