How to Trigger a Warning When Your UPS Switches to Battery

You can script your Mac to perform actions, such as running a command or launching an application, when your uninterruptible power supply (UPS) switches over to the emergency battery.

If your Mac's UPS hardware has switched to battery power, then it is likely the mains power has failed and you need to react as soon possible. Being able to automate your response will save you time and stress when the power fails.

We have previously walked through how to perform a command when a laptop switches from mains power to battery power. Today we are going to modify that recipe to deal with UPS hardware.

As a response to the power failing, let's make the Mac speak when the UPS switches over to battery power. With Power Manager you can schedule an application to launch, documents to open, or any other command or script you like.

Create a UPS Triggered Command Line Event

  1. Launch System Preferences and select Power Manager.
  2. Click Add… to create a new event.
    Click Add to create a new Power Manager event
  3. Choose the template Run a script on battery.
    Select the Run a script on battery task template
  4. Click Continue to the Script step.
  5. Copy and paste your shell script into the Script step.
    say "Switching to UPS battery power."
    Copy and paste in the shell script to run
  6. Continue through the remaining steps until your event is created.
    Continue passed the Constraints step
    Continue through the Why step
    Confirm the creation of your event
    An internal battery triggered event is scheduled

    At this point, the event will be triggered by any connected power source switching to battery power. For our purposes, we are going to modify the event to trigger only when a UPS changes to battery. To do this we use Power Manager's event editor.

  7. Open your event using the event editor; hold down the Option key on the keyboard and double-click on the event.
    Option + double-click the event to show the event editor
  8. Edit the event's trigger; click on the cog in the top-right of the trigger and select Edit.
    Click the trigger cog and select Edit
  9. Add the optional Filter setting to the trigger; click on Optional pop-up menu in the bottom-left of the trigger and select Filter.
    Use the Optional menu to add a Filter
  10. Select USB Connected Power Supply from the Filter pop-up menu. If your UPS is connected via a serial cable or over the network, choose the appropriate alternative.
  11. Click Apply at the bottom-right of the trigger.
    Apply and Save the changes made in the Power Manager event editor

    Note the new Filter by power source text that appears under the trigger's description.

  12. Click Save to confirm your changes to the event.

After following the above steps, your UPS event is scheduled and ready.

To test your new event, try disconnecting your mains power from your UPS. A moment after disconnecting, your Mac will speak and warn that you are now running on battery power.

This article was posted in , , and and tagged , , , and .

Published by Graham Miln on