Scripting On Demand Events

Sample AppleScripts for scripting Power Manager's on-demand events.

Add On Demand Behaviour to an Event

Adds on demand behaviour to an event.

tell application "Power Manager"
    -- Copy the desired event to the workshop
    duplicate the (first event whose name is "Break") of the Event Store to the end of the events of the workshop
    set myEvent to the last event in the workshop
    
    -- Set the event's behaviours
    set behaviours of myEvent to [can perform on demand]
    
    -- Deploy the modified event
    tell Event Store to store these events myEvent
    
    -- Clean up the workshop
    empty workshop
end tell

Remove On Demand Behaviour from an Event

Removes all behaviours from an event.

tell application "Power Manager"
    -- Copy the desired event to the workshop
    duplicate the (first event whose name is "Break") of the Event Store to the end of the events of the workshop
    set myEvent to the last event in the workshop
    
    -- Delete the event's existing behaviours
    delete behaviours of myEvent
    
    -- Deploy the modified event
    tell Event Store to store these events myEvent
    
    -- Clean up the workshop
    empty workshop
end tell

Performing an Event On Demand

Perform the first on demand event.

tell application "Power Manager"
    tell On Demand
        perform event with id (id of first event)
    end tell
end tell

Performing an Event By Unique Identifier (ID) On Demand

Perform the on demand event with the unique identifier 3C6C93FC-2D4C-4514-96ED-5867A0E25B34.

tell application "Power Manager"
    tell On Demand
        perform event with id "3C6C93FC-2D4C-4514-96ED-5867A0E25B34"
    end tell
end tell

Performing an Event By Name On Demand

Perform the on demand event with the name “My Event”.

tell application "Power Manager"
    tell On Demand
        set myEventID to id of events whose name is "My Event"
        perform event with id myEventID
    end tell
end tell