Bunch provides an AppleScript dictionary that you can use to open, close, and toggle Bunches, process raw text, or access snippets.
- Open, close, and toggle Bunches
- Process raw Bunch text
- Snippets, fragments, and variables
tell application "Bunch" to open bunch "Comms" tell application "Bunch" close bunch "Default" toggle bunch "Comms" end tell
You can also process raw Bunch text:
tell application "Bunch" process text "(dnd on)" end tell
\nin the string to add newlines, useful for adding dashed parameters/variables when calling scripts or snippets.
Tip: raw text processing is also useful in scripts where you want to read in the contents of a Bunch, modify them in some way, then execute the result. It won’t mark that Bunch as “open” when it executes, but it’s one way to add dynamic processing.
You can access snippets directly with options to target fragments and pass variables.
run snippet text ¬ fragment text ¬ with variables text
|direct parameter||required||text||snippet path, absolute or relative to configured Bunch folder|
|with variables||optional||text||query string formatted list of key/values|
with variables parameter accepts a string of text formatted like a URL query string, with
key=value pairs separated by ampersands (&). If your value needs to include an actual ampersand, url encode it as
%26 in the query string.
tell application "Bunch" run snippet "useful.snippets" fragment "Spotify" with variables "url=spotify:playlist:4AEt6vXGJYmyOEE8zzgvjQ&autoplay=false" end tell
You can retrieve several of Bunch’s preferences using AppleScript, which avoids the need to use
defaults in shell scripts.
tell application "Bunch" get preference "Bunch Folder" end tell
All values are returned as text. Boolean values (which is everything other than “Bunch Folder” and “Debug Level”) will return text containing either “0” (false) or “1” (true). Debug Level returns text containing a number between 0 (errors only) and 4 (debug messages).
When returning a preference, Bunch just looks for keywords. As long as the text given to
get preference includes one of the following words, it will return the associated preference:
|“folder” or “directory”||Bunch Folder|
|“single”||Single Bunch Mode|
|“debug”||Debug Level (0-4)|