Create Scripts
Create scripts to automate TaskPaper and integrate with other apps.
Getting Started
function TaskPaperContextScript(editor, options) {
return editor.selection.selectedItems.map(
function (item) {
return item.bodyString
}
)
}
Application("TaskPaper").documents[0].evaluate({
script: TaskPaperContextScript.toString()
})
- Open the "AppleScript Editor" application.
- Paste the above script into a new editor window.
- Make sure that the scripting language is set to "JavaScript".
- Run the script and the text of each selected item displays in the AppleScript Editor Results area. You've run a script!
See the Scripting API for API level documentation.
TaskPaper's JavaScript Context
TaskPaper specific scripting happens in TaskPaper's JavaScript context.
Use the evaluate
command to pass JavaScript code into TaskPaper's JavaScript Context. The script that you pass in is then evaluated and run within TaskPaper in a JavaScript context.
In the Script Editor context:
- Your script is running within Script Editor.
- Your script can interact with other scriptable applications.
- Your script can access TaskPaper's standard scripting suite objects such as the documents list.
- Your script makes calls to TaskPaper's
evaluate
command. - Your script may use JavaScript or AppleScript syntax.
In the TaskPaper JavaScript context:
- Your script must use JavaScript syntax.
- TaskPaper uses Javascript's
eval
function to create a function from your script. - Your script is then run from within TaskPaper's JavaScript context.
- Your script can interact with TaskPaper's model objects such as the OutlineEditor.
- Your can use TaskPaper's Window > JavaScript Debugger to debug your script.
Debugging TaskPaper's JavaScript Context
To debug your script (TaskPaper 3.2 and above):
- Open Safari
- Open TaskPaper
- Ensure Safari’s “Develop” menu is showing.
- Choose Safari > Develop > Computer > TaskPaper > birch.html
You should now see a debug window for TaskPaper’s JavaScript context. Add a debugger
statement to your script and your script will pause at that point in the debugger window. For example:
function TaskPaperContextScript(editor, options) {
debugger;
}
Application("TaskPaper").documents[0].evaluate({
script: TaskPaperContextScript.toString();
})
Note Debugging won't work in the Mac App Store version of TaskPaper. It works with the version of TaskPaper that you download from TaskPaper.com. If you have purchased the Mac App Store version run it once on your computer. Then you can run the direct download version without having to buy a second license.
Cross-Platform Scripts
Birch-outline enables cross-platform scripting for TaskPaper.
Use birch-outline to parse, process, and save TaskPaper files wherever you have JavaScript. It's not just a parser. Birch-outline also includes TaskPaper's runtime model–Giving you the same scripting behavior that you have when scripting TaskPaper.app.