Fruit Bat Docs

Roost

Roost, the command line and scripting language built into Fruit Bat: every setting, page and panel from the keyboard, Roost Basic, Roost Script and .roost files.

A command line for Fruit Bat along the bottom of the window: the >_ Roost toolbar button, menu › Roost, or Ctrl+**. Type **help** to list the commands, or **help ` for one, with examples.

  • Pipes: | passes tabs, links or text from one command to the next. tabs | grep -i bat | group "Bat research" --color green links | grep pdf | head 3 | open page | ask "what are the three main points?" history --since yesterday | grep -i recipe | open tabs --site youtube.com | close
  • Commands:
    • Tabs: tabs [--asleep|--awake], go, close, pin, unpin, mute, unmute, reload [--hard], group, new [--window|--private|--vampire], sleep (the tabs piped in or numbered; on its own, every other tab), wake, duplicate (or dup), windows, window min|max|close|quit.
    • Tree tabs (tabs on the side): nest N (nest the tabs piped in under tab N), unnest, fold, unfold.
    • Pages: open [--here], back, forward, home, stop, url [--clean] [--copy], page [--css SELECTOR], links, find, reader, zoom, media [play|pause|mute|unmute|loop|pip|speed X|controls], fullscreen, print-page, devtools, qr [TEXT], screenshot [--save].
    • Acting on a page: click "text", fill "field" "text", press enter|escape|tab|…, type "text", hover "text", scroll top|bottom|up|down, wait-for "text" [--gone].
    • Groups and order: group (joins a group of that name if there is one; --new for a fresh one), ungroup, collapse, expand, move --start|--end|--to N|--window N|--new-window.
    • Library: history, forget, bookmarks [FOLDER] (a folder includes its subfolders), bookmarks --folders, bookmark [--to FOLDER], bookmark --rm (this page or the bookmarks piped in).
    • Echo: ask, summarize, translate, translate --page [--to LANGUAGE] (the page itself, in place), translate --original, translate --stop, panel echo.
    • Chat (Chirp): chirp, chirp unread, chirp read #channel [-n 20], chirp say #channel "text", chirp share #channel, chirp join, chirp part, chirp open, with --net NAME when you're on several networks. At most 5 messages a minute.
    • Torrents (Colony): torrent (or colony), torrent add LINK (or pipe links in), torrent pause|resume N|all, torrent remove N [--files] (asks first), torrent files N, torrent stats, torrent open [N]. Colony has to be on (Settings › General).
    • Wallet (Web3): wallet, wallet balance, wallet address, wallet accounts, wallet networks, wallet network NAME, wallet activity, wallet sites, wallet disconnect SITE, wallet lock, wallet open.
      • wallet send 0.01 ETH to 0x… only prepares a payment; nothing is sent until you press Approve in the wallet panel. It works only when you type it (never from scripts, jobs or Echo).
      • The wallet has to be on (Settings › Wallet). It's never available in Vampire Bat windows.
    • Browser, privacy and system:
      • perms (every site you've decided for), perms SITE, perms set SITE camera|microphone|location|notifications|… allow|block|ask, perms reset SITE.
      • storage [--site SITE] (what sites keep, largest first), storage clear SITE (asks first; signs you out of it).
      • network [TAB] [--trackers]: the sites a page contacted, their owners, and what Lime Blocker stopped.
      • saver [on|off|auto|unplugged|snooze]: battery saver.
      • ext, ext on|off|pin|unpin|open|settings NAME: extensions (part of the name is enough).
      • status [refresh]: Fruit Bat's services from status.fruitbat.app. tor, tor new (a new identity, in Vampire Bat).
      • top [-n 10]: what's using memory and processor; your own tabs pass along (top -n 3 | sleep). sysinfo: about:system as text (sysinfo | copy).
      • hidden [SITE], hidden clear SITE: elements you hid with Lime Blocker.
      • In Roost Script they're functions as usual: sleep(tabs({ older: "2h" })), perms("meet.google.com"), top({ n: 3 }).
      • Echo and scripts from files can sleep, wake and duplicate tabs and look with all of these, but never change permissions, clear site data, change battery saver, turn extensions on or off, or clear hidden elements.
      • Private windows can't change permissions, site data or extensions (they'd record the sites you visit); Vampire Bat windows can't sleep tabs, and top and windows never show other windows' private tab titles.
    • Settings, pages and the rest of the browser:
      • config lists every setting with its value (config sleep filters), config get NAME, config set NAME VALUE, config reset NAME, config open [SECTION] (also settings). Values go through the same checks as the Settings page, and settings that affect privacy or security (Lime Blocker, HTTPS-Only, history, Tor, the wallet, Echo in private windows…) ask first.
      • about lists Fruit Bat's own pages; about tasks, about settings, about history… opens one.
      • panel echo|wallet|chirp|ADD-ON|ext NAME|close: side panels.
      • passwords (this site's usernames), passwords all, passwords fill (opens the fill menu; you pick), passwords open. autofill (your addresses and cards by name and last four digits), autofill fill address|card, autofill open. Roost never shows, copies or types a password, card number or address.
      • addons, addons on|off|private|open NAME: Fruit Bat add-ons.
      • update, update check, update restart, update channel stable|beta.
      • logs [SOURCE] [WORDS] [--level warn|error] [-n 50]: about:logs as text (logs tor, logs updates | grep failed).
      • schedule, schedule every 2h NAME, schedule daily 08:30 NAME [--weekdays], schedule startup NAME, schedule run|remove NAME: run saved scripts on a timer, even with Roost closed.
      • downloads [--done], downloads pause|resume|cancel|retry|show|open|remove N, downloads clear, downloads folder (open asks first).
      • Echo can read settings, logs and the update status, open Fruit Bat's pages and panels, and play or pause media (you press Run). It can never change settings, switch add-ons, restart, open or remove downloads, take screenshots, print, or use passwords or autofill. Scripts from files get the same.
    • Other: get, blocked, lime on|off|refresh|receipt, notify.
    • Lists: grep [-i] [-v], sort [-r], head, tail, uniq, wc, echo.
    • Aliases: ls (tabs), cd (go), man (help).
  • Tab numbers count from the left (or the top with vertical tabs), as tabs shows them.
  • Keys: Tab completes, ↑/↓ for earlier lines, Ctrl+R searches them, Ctrl+C stops or answers no, Ctrl+L clears, Esc clears the line.
  • Safety:
    • Roost only does what you could do by hand in the browser; it can't touch your files or run programs (save, screenshot --save and downloads open ask first).
    • Everything in Settings, every Fruit Bat page and every side panel can be reached from Roost. What's left out on purpose: showing secrets (passwords, card numbers), importing from other browsers (it needs the other browser closed and you watching), and Safe Mode (about:system).
    • It asks before closing more than 3 tabs, opening more than 5, forgetting a site, downloading, opening a downloaded file, saving a screenshot, closing a window with tabs, quitting, or changing a privacy or security setting.
    • Commands that change something must come last in a line, and a line with a mistake anywhere doesn't run at all.
    • Text from websites (tab titles, page text, links) is shown only as text and goes to Echo marked as untrusted.
    • click, fill, scroll and wait-for work only on web pages, never on Fruit Bat's own pages.
    • click asks first when the button sounds risky (buy, pay, delete, send, submit, sign out and similar).
    • fill, type and value() refuse password, card, one-time-code and other secret fields.
    • press enter asks first when the form's button sounds risky.
  • Private and Vampire Bat windows: Roost sees only that window and keeps typed commands in memory only. Vampire Bat's Roost can't see history or bookmarks.
  • Not yet: the system terminal (a real bash/PowerShell tab), cookies, and the developer commands (request, headers).

Scripting: two languages#

Roost has two scripting languages. They share the same commands, limits and safety rules.

  • Roost Basic is the command-line style below (help scripting). It's the default.
  • Roost Script looks like JavaScript (help roost-script). See the next section.

Roost Basic#

Saved scripts are a small language on top of Roost commands; help scripting explains it.

# tidy: close YouTube in the evening, pin the bat tabs
set yt = $(tabs --site youtube.com)
if count($yt) > 0 and hour() >= 18
  echo "Closing $yt.count YouTube tabs"
  $yt | close --yes
end
for tab in $(tabs --unpinned)
  if $tab.title contains "bat"
    $tab | pin
  end
end
  • Statements: set, print, if/else if/else/end, for … in … end, repeat N … end, while … end, try … catch [name] … end, break, continue, stop, fail, wait, vars, unset.
  • try/catch: a failed line inside try jumps to catch with the reason in $error. Ctrl+C, answering no, and the runaway limits can't be caught.
  • Browser functions: title(), url() and tabcount() read the current tab and window.
  • Page checks: has("text"), exists("button text"), read("css"), readall("css"), value("field"), for example if exists("Accept all").
  • Editor: script new NAME opens it. It's coloured, has line numbers, and marks the line with a mistake as you type.
    • Ctrl+S saves, Ctrl+Enter runs the lines without saving, Ctrl+Shift+Enter (Step) asks before each command, and Ctrl+E goes back to it.
    • run NAME --step steps through a saved script.
  • Values: numbers, "text" (with $var inside), 'literal text', [lists], $(command output) and $var.field. Tabs have .title, .url, .site, .number, .pinned and more.
  • Safety: values put into commands are always quoted. Loops stop at 1000 rounds, a run stops at 20,000 steps, and wait is capped at a minute. Ctrl+C stops a script.

Roost Script (JavaScript style)#

A script is Roost Script when its first line is // roost script. script new NAME --js starts one, and the editor's language menu switches a script between the two (it changes the first line, not your code). At the prompt, js … runs one line.

// roost script
// tidy: close YouTube in the evening, pin the bat tabs
const yt = tabs({ site: 'youtube.com' })
if (yt.length > 0 && hour() >= 18) {
  print(`Closing ${yt.length} YouTube tabs`)
  close(yt, { yes: true })
}
for (const tab of tabs({ unpinned: true })) {
  if (tab.title.toLowerCase().includes('bat')) pin(tab)
}
  • Commands are functions. tabs({ site: 'x' }) runs tabs --site x and returns the tabs. Options go in a last { }; true gives a flag. Dashes become capitals: waitFor('Sign in').
  • Lists go in as arguments (close(list)), or pipe with a dot: links().grep(/pdf/i).head(3).open().
  • Commands with actions: chirp.say('#rust', 'hi'), wallet.balance(), torrent.pause(2).
  • Output: a command on its own line shows its output, like Roost Basic. Used as a value it's quiet and returns its result (items, or text).
  • The language:
    • let/const, if/else, for…of, for (;;), while, do…while, switch, break, continue;
    • functions and arrows (closures), default and rest parameters, destructuring and ...spread;
    • try/catch/finally and throw new Error('…');
    • templates, /regex/ (simple patterns only), ?., ??, typeof.
  • Built in: print, console.log, wait('2s'), fail, stop, range, Math, JSON, Object.keys/values/entries, text and list methods, plus Roost Basic's page checks and browser functions (has(), exists(), read(), readAll(), value(), title(), url(), tabCount()…).
  • Classes: fields, constructor, methods, static, extends, super, new, this, instanceof; classes can extend Error. No getters/setters or #private fields.
  • Not included: async/await (everything already waits), imports and eval. Scripts can't reach Node, the network or files, only Roost's commands.
  • Safety: the same limits as Roost Basic (1000 rounds per loop, 20,000 steps, 2,000-item lists), plus a 200-deep call limit. Ctrl+C, answering no and the limits can't be caught. Step (Ctrl+Shift+Enter) asks before each command.
  • Echo: Settings › General › Language for Echo's Roost scripts picks which one Echo writes. Every command a Roost Script card names is checked with Echo's rules on the card, and each command line is checked again as it's built while the script runs (so a command made up at run time can't slip through). { yes: true } is refused.

Script words, memory and the toolbar#

  • Words: tidy youtube.com gives the script $1 (Roost Basic) or args[0] (Roost Script). $args / args hold every word.
  • Memory: remember price 18.99 keeps a value for the next run; recall("price", 0) reads it back.
    • Each script has its own memory, and so does the prompt.
    • Stored under the roostMemory setting. Never written from private windows; off for Echo's scripts and .roost files.
  • Outside the panel: script pin NAME (or On the toolbar in the editor) adds the script to the toolbar's ▶ button, and the page's right-click menu has Run Roost script ›.

.roost files#

A Roost script (either language) can be saved as a .roost file to keep or share: script export NAME.

  • Opening one:
    • double-click it (Fruit Bat registers .roost files);
    • drop it on a page;
    • type or paste its path into the address bar;
    • script open;
    • open it from Downloads.
  • Nothing runs straight away. Roost shows the script, checked line by line, and asks: y runs it, e opens it in the editor, Enter cancels.
  • Outside-script rules: a file runs with Echo's rules, because a file can come from anyone.
    • Only Echo's commands. No --yes.
    • Roost Script commands are checked again as they're built.
    • At most 30 new tabs and 100 clicks per run; 500 lines per file.
    • Saving it from the editor makes it your own script, with every command.

Aliases, scripts, automation and sessions#

  • Aliases:
    • alias name = command… (pipes and all).
    • Words you type after an alias are added to its end, e.g. alias site = tabs --site, then site github.com.
    • alias lists them, unalias name removes one. They can't shadow built-in commands.
  • Scripts:
    • script new name / script edit name opens the editor (Ctrl+S saves, Esc closes). script ls, script show name and script rm name manage them.
    • Run one by typing its name or run name.
    • A script can run from Ctrl+Alt+letter (⌘⌥ on Mac; R is taken by Reader view) or when Fruit Bat opens. If Roost is closed when it runs, its output waits there and a note says it ran.
    • Lines stop at the first failure. Commands that ask first need --yes inside a script; scripts can call scripts 3 deep. # morning open mail.example news.example calendar.example | group Morning --color blue session save before-tidy tabs --older 1w --unpinned | close --yes
  • Automation (per window):
    • every <time> <command…> and after <time> <command…>, with times like 30s, 10m, 2h or 1d. every runs at most once a minute.
    • watch [tab] [--css sel] [--every 5m] [--reload] reports changes in Roost, as a note in the window and as a system notification (normal windows).
    • jobs lists what's running and kill N / kill all stops jobs. There are at most 10 per window; they end with the window and aren't saved.
  • Sessions: session save name [--close], session open name, session ls, session show name, session rm name. Groups and pinned tabs are kept. Normal windows only.
  • Output:
    • copy [--csv|--json] puts results on the clipboard.
    • save [name] [--csv|--json] asks first, then writes only to Downloads, never overwriting.
    • json shows results as JSON.
  • Tab filters: --older <time>, --dupes, --group <name>, --pinned, --unpinned, --playing, --muted, --site <site>.

Full reference#

Every command, function and example is in the Roost docs at docs.roostlang.org.