Scripting the Events

Counting Events

Get the number of Events.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     set numEvents to count PMEvents
4
    end tell
5
end tell

Open in Script Editor

Counting Daily Events

Get the number of Events with Daily triggers.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     set numEvents to count (PMEvents whose type class of trigger is daily)
4
    end tell
5
end tell

Open in Script Editor

Looking for Existing Events

Say 'Morning exists.' if an Event called "Morning" exists.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     if exists (PMEvent "Morning") then
4
         say "Morning exists."
5
     end if
6
    end tell
7
end tell

Open in Script Editor

Add an Event

Creates a new Start Up or Wake Event triggered Once in an hour.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     add event {enabled:true, unique id:"in-one-hour", name:"Wake up in one hour!", trigger:{type class:once, date:((current date) + (60 * 60))}, action:{type class:start up or wake}}
4
    end tell
5
end tell

Open in Script Editor

Copy an Event

Finds an Event by name, copies its properties, and adds a new Event with a slightly different name.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     -- Copy the Event "Morning"
4
     set myEvent to properties of PMEvent "Morning"
5
     set trigger of myEvent to properties of trigger of myEvent
6
     set action of myEvent to properties of action of myEvent
7
     -- ...modify as needed
8
     add event myEvent
9
    end tell
10
end tell

Open in Script Editor

The add command needs a record of properties. The properties returned by properties of PMEvent "Morning" include references to other records - we need to resolve those references ourselves; thus the following two lines setting trigger and action.

Rename an Event

Finds an Event by name, modifies it name, and resubmits the updated copy.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     -- Copy the Event "Morning"
4
     set myEvent to properties of PMEvent "Morning"
5
     set trigger of myEvent to properties of trigger of myEvent
6
     set action of myEvent to properties of action of myEvent
7
     
8
     -- Rename our copy
9
     set name of myEvent to "Second Dawn"
10
        
11
        -- Resubmit the event
12
        add event myEvent
13
    end tell
14
end tell

Open in Script Editor

The copy, modify, and add works to modify the existing Event because we do not change the unique id.

Disable an Event

Finds an Event by name, disables it, and resubmits the updated copy.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     -- Copy the Event "Morning"
4
     set myEvent to properties of PMEvent "Morning"
5
     set trigger of myEvent to properties of trigger of myEvent
6
     set action of myEvent to properties of action of myEvent
7
     
8
     -- Disable our copy
9
     set enabled of myEvent to false
10
        
11
        -- Resubmit the event
12
        add event myEvent
13
    end tell
14
end tell

Open in Script Editor

Remove an Event by Name

Removes an Event by name.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     remove unique id (unique id of PMEvent "Morning") as string
4
    end tell
5
end tell

Open in Script Editor

Remove all Events

Remove all Events from the schedule.

Fetches all the unique ids into a list and passes item of the list to the remove command.

Line  
1
tell application "Power Manager Scripting"
2
    tell scheduler
3
     set everyID to unique id of every PMEvent
4
     repeat with anID in everyID
5
         remove unique id anID
6
     end repeat
7
    end tell
8
end tell

Open in Script Editor