The Pennyworth Project

Just another WordPress site

Creating custom sensors with AppleScript

Genkanban ships with a variety of default sensors, but it also includes some functionality that allows you to create your own sensors using AppleScript. The process is simple and I’ll demonstrate it by creating a sensor that detects your currently selected weblog in MarsEdit.

Before we get into the details, here are some general notes about the AppleScript sensors:

1. AppleScript sensors are standard .scpt files authored in Script Editor.

2. The AppleScript files should be placed in the folder at

~/Library/Application Support/Genkanban/AppleScript/Sensors

3. On a set duration (currently 10 seconds), Genkanban scans that folder, and executes each script located within. The predictions generated by each script last for the set duration and will disappear once that duration expires or the observation is renewed on the next pass.

4. Scripts return observations by returning a semicolon-delimited string of key-value pairs in the form

key1=value1;key2=value2;...;keyN=valueN

The keys and values may contain any character, save “=” and “;”.

5. Genkanban translates the key-value pairs as separate observations in the form

AppleScript Observer (KEY) = VALUE

That said, let’s create a sensor for MarsEdit.

1. First, we need to create a script file to return the selected weblog. In Script Editor, enter the following script:

tell application "Finder"
    repeat with p in (processes whose name is "MarsEdit")
        tell application "MarsEdit"
            return "Marsedit: Current Blog=" & name of selected weblog
        end tell
    end repeat
end tell

Wrapping the call with the call to Finder allows us to only return a value when MarsEdit is actually running. If this was not included, the sensor would launch MarsEdit (if closed) each time it ran.

2. Test the script by running it with MarsEdit open and closed. When close, it should return nothing. When open, it should return something like:

"Marsedit: Current Blog=The Context Blog"

3. Save the script file and put it in the location mentioned above.

4. If Genkanban is running, in less than ten seconds, the script will be executed and the results will be visible in the observations window:

Genkanban: AppleScript observer

5. Congratulate yourself on a job well done.

Some parting thoughts: At the moment, Genkanban uses a ten second interval for executing and retiring observations. I may extend this interval to longer period or make it user-configurable. There’s a tradeoff between having reliable current observations and executing the scripts too often that I’m still negotiating.

Posted by admin at 12:41 pm on February 5, 2008 . Filed under Pennyworth.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.