FlexTime supports AppleScript in two important ways. First, by allowing any cue action to be handled by a custom script, and second by providing a rich scripting dictionary of its own, allowing any routine document to be extensively modified by way of AppleScript.
Scripted cues are any that make use of the built-in "Run Script" cue action. This action is slightly misleading in its name, since it's capable of running quite a bit more than a plain AppleScript. Applications, shell scripts, automator workflows, and even document files may all be run/opened/activated by this powerful cue action.
In this section I'll focus on the features of FlexTime that enable an AppleScript to powerfully extend the cueing mechanism. For starters, let's examine one of the simplest possible scripted cues. Copy and paste the following script into a Script Editor document:
beep delay 0.5 beep
Now, save the file to disk, calling it something like "DoubleBeep." From FlexTime, you can now choose this script as the "Run Script" parameter for any cue, and suddenly your arsenal of cue types has been expanded!
This example is trivial, but the possibilities are endless. To facilitate even more powerful scripted cues, FlexTime takes advantage of an AppleScript feature allowing a script to expose a "handler" of a particular name. If this handler exists in your script, FlexTime passes special information about the activity and document that are being handled. You may reference attributes of these objects and choose an appropriate action. For example, the following script uses information from FlexTime to present a customized "Show Text" type message:
using terms from application "FlexTime" on HandleFlexTimeCue(myDocument, myActivity) -- And ask FlexTime to show a message set routineName to name of myDocument set activityName to name of myActivity set myText to "Time to do " & activityName & " for " & routineName tell application "FlexTime" display message myText at screen position bottom left ¬ dismissing after delay 5 end tell end HandleFlexTimeCue end using terms from
The list of attributes you may ask for from "myDocument" and "myRoutine" is cataloged in the AppleScript dictionary for FlexTime, described in more detail in the next section.
In addition to running scripts, FlexTime is itself highly scriptable. This means that scripts you write and run - from FlexTime or from another application - can be used to modify or access data from within your FlexTime routine documents. For a complete description of the scriptable objects that FlexTime makes available to you, use Script Editor's "Open Dictionary" menu item to browse the FlexTime dictionary. A brief summary of each of the highest level scripting objects is given here to give you a sense of what is possible:
application - The highest level scriptable object is the application itself. From this object you can ask FlexTime to open or create routine documents, as well as refer to open documents by index or name.
document - The document object represents an open routine. You may change a document's name, access or create activities, and change the running state (start or stop a routine) by way of this object.
activity - The activity object represent a single item from the schedule of a particular routine. You may change the name, and alter the settings for any of the cues on the activity.
cue - The cue object contains information about the cue action and its parameter. You can manipulate the settings of any activity's cues through this object.