Triggering an Event from the Command Line

Power Manager events can be be triggered from the command line - often referred to as from the shell. This ability allows you to incorporate your events into other scripts and to trigger events through a remote secure shell connection (ssh).

Power Manager events can be be triggered from the command line - often referred to as from the shell. This ability allows you to incorporate your events into other scripts and to trigger events through a remote secure shell connection (ssh).

To trigger an event from the command line, the event must support on-demand behaviour. On-demand behaviour is a setting within an event that states the event can be performed without a specific trigger firing.

Most events created with the Schedule Assistant already have on-demand behaviour set up for you. If the behaviour is not set, you can add on-demand behaviour to any event using the event editor.

To trigger the event, we are going to use the command line tool pmctl. This tool is included with Power Manager and provides complete access to Power Manager from the command line.

Finding the Unique Identifier

The API request needed to trigger an event is called ondemand.perform. This request requires one parameter, the unique identifier of the event.

A unique identifier is embedded within every event. The unique identifier is how Power Manager works with and manages your events. An event’s name is not considered unique and is not used internally.

To view the unique identifier of an event, use the Power Manager application to expand an event. The unique identifier is revealed with the label ID. You can copy and paste your event into a text editor to get this value without needing to type it out.

Power Manager event expanded to reveal the unique identifier.

Power Manager event expanded to reveal the unique identifier.

Triggering the Event

With the event’s unique identifier known, we can ask pmctl to trigger the event for us.

  1. Launch Utilities > Terminal.app

  2. Change directory with the command:

    % cd "/Library/Application Support/Power Manager/Tools/"
    
  3. Issue the perform request:

    % ./pmctl ondemand.perform "unique ID=B334794F-5FAF-4C21-8ED0-4C40D356A521"
    

Triggering a Power Manager event from the command line.

Triggering a Power Manager event from the command line.

Your event will be triggered immediately. Any conditions controlling the event will be evaluated and, if successful, performing of the actions will follow.

This technique can be used to incorporate Power Manager’s events into other tools and workflows. Through pmctl you can interact with Power Manager from any tool or scripting language capable of working with command line tools - this includes perl, python, and ruby among many others.