You can create an event in Power Manager to automatically perform tasks when the computer's battery reaches a specific charge. In this recipe, we will create an event that runs a script when the battery reaches 90% charged.
Power Manager already includes a Schedule Assistant task for running scripts when the battery charge drops, but not one for when the battery charge rises. This recipe shows how to create a battery rising triggered event using Power Manager's built-in Event Editor.
Let's walk through creating an automatic run script on power remaining event.
- Launch and unlock Power Manager.app
- Add a new empty event; select the menu item: File > New > New Event…
- Open the event in the Event Editor; select the event, then select the menu item: Edit > Edit in Event Editor
- Add a Power Remaining trigger; select the pop-up menu item: Add a trigger > Power Remaining > Battery 90% Charged The trigger can be edited to adjust the power source involved and charge behaviour.
- Add a Run a Script action; select the pop-up menu item: Add an action > Run Script > Shell Script The initial shell script does nothing.
- Edit the script action to speak when performed; select Edit from the Action's pop-up menu (top-right … icon), or double-click on the action.
Extend the script with the
#!/bin/sh say "Battery 90% charged."
- Save the changes to the Run Script action.
Name the event and add the Optional behaviour Can Perform On Demand; select Edit from the Event's pop-up menu (top-right … icon), or double-click on the event name.
Change the name to Nearly Charged.
Select the pop-up menu item Optional > Behaviours and select the checkbox Can Perform On Demand.
- Apply and Save to confirm the changes and update the event.
The power remaining event is now ready to test.
By adding the Can Perform On Demand behaviour, you can test the event's embedded script works separately from the event's power remaining trigger. Try triggering the event manually using the Power Manager status menu bar, or through the application. You should hear the computer speak. If this works, you know the action and it's script are correct.
Next test the event's power remaining trigger. This can be done by using the computer's battery and then charging it back up. When the battery's charge percentage passes 90%, the computer should speak.
The Power Remaining trigger can be customised:
The same trigger handles both triggering on the charge rising and falling. It can trigger based on percentage capacity or time remaining. The trigger can also monitor power sources such as Uninterruptable Power Supplies (UPS).