Tutorial: Creating Toolbox Activities
One of the unique features of PowerWF is the ability for users to extend it by adding their own toolbox activities. This tutorial will create a workflow that uses SAPI to speak whatever text is passed to it. This workflow will then be converted into a toolbox activity which can be dropped into other workflows
Topics Discussed
- Naming Activities
- Combining PowerShell and COM
- Using Input Parameters
- Creating Toolbox activities
- Using custom toolbox activities
- Using the ExecScript activity.
- Using the FormatString activity.
- Using the ForEach activity.
- Using the GetProperty activity.
Procedure
- Create a new workflow project called “speakToMe”
- This workflow will utilize the Speech API (SAPI) by using the ExecScript activity from the PowerShell V2 toolbox. Drop an ExecScript activity onto the canvas and set the script to:
$sapi = new-object -com SAPI.SpVoice

This command creates the SAPI object for later use.
- To make the workflow more readable, set the Name of ExecScript1 to “Create SAPI”
- Drop a second ExecScript activity onto the canvas and set the script to:
$sapi.speak(“I hunger”);$sapi.waitUntilDone(10000);
The speak command tells the speech API to say, “I Hunger”. To work properly, the speech API requires that an option be set to wait until the Speak activity is done before proceeding, unless it takes longer than 10 seconds. - For readability, set the Name of ExecScript2 to “SayWords”
- Although PowerWF scripts will run in their own run-space and clean up automatically on shutdown, one more ExecScript activity can be added to clean up the SAPI object. Drop another ExecScript activity on the canvas and set the script to:
$sapi = $null
Set the name of the ExecScript to “CleanupSAPI”
2 years ago - link

