Controlling PowerKey with AppleScript

    AppleScript offers Mac users a powerful way to automate tasks and share information. PowerKey is fully scriptable, allowing your scripts to control your outlets.

    To control PowerKey, place a tell block in your script as follows:

    Mac OS X
       tell application "PowerKey Daemon"
          . . .
       end tell

    Mac OS 8.6-9.x
       tell application "PowerKey Extension"
          . . .
       end tell

    You can then place PowerKey scripting commands inside this block.

PowerKey objects

    The PowerKey software defines several classes of objects for use by AppleScripts. A unit is a single PowerKey Pro containing several outlet elements. An event is a hot key, tone sequence or scheduled event defined in the corresponding panel of the PowerKey control panel.

    You access the properties of units, outlets and events using the AppleScript get and set commands.

       -- Find out the name of an outlet.
       get name of outlet 1 of unit "My PowerKey"
       -- Change the name of an event.
       set name of event "Old Name" to "New Name"

    For more information on PowerKey classes, use the "Open Dictionary" command in the Script Editor's File menu. In OS 8.6 or 9.x, open the "PowerKey Extension" (not control panel) in your system's Extensions folder. In OS X, select "PowerKey Daemon" (not just "PowerKey") in the list of applications.

Switching outlets

    To switch an outlet, you set its level property to 0 (off) or 100 (on). You can also get the level of an outlet to find out if it's currently on or off.

    Note: You must specify both the outlet and the unit, even if you only have one PowerKey Pro. Units and outlets can be specified by name or number. Outlet numbers are fixed, but unit numbers can change every time the computer starts up, so it is best to refer to units by name.

       -- turn on a numbered outlet.
       set level of outlet 3 of unit "John's PowerKey" to 100
       -- Find out if the printer is on.
       if level of outlet "Printer" of unit "My PK" is 100 then
          -- Do printing stuff here.
       end if
       -- Toggle an outlet.
       get level of outlet 3 of unit "Willow's PK"
       get (100 - the result)
       set level of outlet 3 of unit "Willow's PK" to the result
       -- This is dangerous if you have more than one unit!
       get level of outlet 3 of unit 1 -- not always the same unit

Disabling and enabling events

    Scripts can disable events to keep them from running, and re-enable them. To do this, set the enabled property of a unit's event to true or false. This is equivalent to unchecking the event's "On" box in the PowerKey control panel.

       -- Don't let an event run.
       set enabled of event "Nightly Backup" to false
       -- Find out if an event is active.
       get enabled of event "Nightly Backup"

Executing Events

    Scripts can execute an Event's action immediately using the execute command.

       -- Run an event immediately.
       execute event "Modem Hot Key"

Table of contents