Creating Scripts
Last updated
Last updated
Create scripts to automate Bike and integrate with other apps. If you just want to run a script that someone else has written please see the section.
Also consider using Bike's more powerful .
When scripting Bike you are dealing with documents
, windows
, and rows
. Documents and windows are common scripting objects with a few Bike extensions–rows are specific to Bike.
Each row represents a row in your outline. Rows have a name
for accessing the row's text. Rows also have an id
and other attributes. Rows can contain other rows. When you move or delete a row those contained rows are moved or deleted with it.
You gain access to rows in a few ways:
From properties of a document such as root row
, selected row
, focused row
.
From the rows
collection belonging to each document. This collection contains all rows in the document (except for the root). This collection is a good place to quickly find existing rows.
From the rows
collection belonging to each row.
This collection contains only the rows that are directly contained by the row (the children). This collection is a good place for making new rows and to use as a target to moving existing rows into.
Use Bike's scripting dictionary to learn what parts of Bike are scriptable.
Drag and drop Bike onto Script Editor's application icon.
Or from Script Editor use File > Open Dictionary and choose Bike's dictionary.
Here's the official starting point for learning AppleScript:
The starting point for lesser people, such as myself, is to find example scripts and then randomly change them until they do what you want. I've included some for you below. You can also find scripts in the Bike support form and ask scripting questions.
This is a nonsense script that demonstrates many of Bike's scripting abilities. It's a good place to learn how basic things are done like making and moving rows.
This script resets your view state to "Home"
This script saves the current selected row. Collapses all rows. Then restores your selection, which also expands any rows needed to show the selection. Use it to cleanup when you have to many rows expanded, but you still want to keep working where you are.
This script create a simple calendar structure in your outline and adds a new line to "today" where you can start taking notes. It's interesting because it uses row id
's to track rows. Once the calendar is created you can move it to any place in your outline and the script will keep working.
Why might you want to do this? Generaly, Bike's app context extension API is faster and more powerful than the AppleScript API. This lets you jump from AppleScript land, to Bike extension land, and then back to AppleScript land again.
Note: The script run function that you pass should be plain JavaScript, not the TypeScript code used in most of the extension API documentation.
Here's a explanation of each step in the process:
Call run extension script command
Pass in the string representation of a Javascript function named "run"
Pass in some options, in this case the string "From Applescript"
Bike will then parse that Javascript function and install it in Bike's app extension context
Bike will then call the run
function, passing in the provided options (if any)
The function will log the passed in options–use Window > Logs Explorer to see results
The function also returns the string "From App Extension Context"
And you should see that result printed in Script Editor.
You'll get the most out of these scripts by using instead of Script Editor that comes with your Mac. Among other things Script Debugger allows you to step through the script line by line so you can see the effect of each command on you document.
You can call from ApplesScript into Bike's app API using run extension script
.