Skip to content

Browser and terminal tabs

People switch between tabs, not windows. aos window sees one Chrome window; the thing you want is the pull request in its ninth tab, or the terminal tab sitting in ~/src/aos. aos tab reaches inside the window.

  • A browser or a terminal is just a window kind: aos window list now prints browser, terminal, editor, files or other, and --kind= filters on it.
  • Each app is asked in the language it speaks: AppleScript (JXA) on macOS, UI Automation on Windows, the accessibility tree as the catch-all.
  • Apps that are not running are skipped, never launched.
Terminal window
$ aos window list --kind=terminal
* Ghostty terminal mon 2 1920x963+0+30 host.local: deemwar-one-os
Ghostty terminal mon 1 864x1084-864+33 me@host:/private/tmp
$ aos tab list --app=chrome
chrome:1658109204:1658109205 browser Example Domain https://example.com/
* chrome:1658109204:1658109210 browser Example Domains https://www.iana.org/help/example-domains
chrome:1658109204:1658109212 browser aos-bg-test data:text/html,<title>aos-bg-test</title>bg

* marks the selected tab of each window. Terminals print the folder instead of a URL, and split panes indented under their tab:

Terminal window
$ aos tab list --app=ghostty --window=tab-group-8039faee0
ghostty:tab-group-8039faee0:tab-802a71200 terminal me@host:/private/tmp /private/tmp
* ghostty:tab-group-8039faee0:tab-802a71c00 terminal me@host:/usr /usr
* ghostty:tab-group-8039faee0:tab-802a71c00:41E9EDB7-DBC0-43E6-9A86-EE7ED8CCF27F me@host:/usr /usr
ghostty:tab-group-8039faee0:tab-802a71c00:C8A30C61-013D-4EB2-A97E-2D301201105D me@host:/var /var

--json gives every field an agent needs:

Terminal window
$ aos tab list --app=ghostty --json
[
{
"id": "ghostty:tab-group-8039faee0:tab-802a71200",
"app": "Ghostty",
"kind": "terminal",
"window": "22626",
"native_window": "tab-group-8039faee0",
"index": 1,
"title": "me@host:/private/tmp",
"cwd": "/private/tmp",
"active": true,
"source": "applescript"
}
]

window is the aos window id from window list, matched by app, bounds and title. native_window is the app’s own id. Listing 63 Chrome tabs takes about 100 ms: aos reads every title and URL in one request instead of one per tab.

Name it by title, URL, folder or id. aos raises the window and selects the tab.

Terminal window
$ aos tab focus --title=aos-bg-test --app=chrome
chrome:1658109204:1658109212 aos-bg-test
$ aos tab focus --url=iana.org --app=safari
safari:22718:2 Example Domains
$ aos tab focus --cwd=/usr --app=ghostty
ghostty:tab-group-8039faee0:tab-802a73a00 me@host:/usr
$ aos tab focus --title=nomatchxyz
aos: no tab matched title="nomatchxyz"
$ echo $?
3

Matching is a case-insensitive substring; --exact wants the whole title, URL or folder. When several tabs match, the selected one wins, else the first. A pane id focuses that split.

The new tab’s id is printed, ready for focus, send or close. The tab opens in the background: the window is not raised, the app is not activated and your current tab stays selected. Pass --focus to bring it forward.

Terminal window
$ aos tab open https://www.iana.org/help/example-domains --app=chrome --window=1658109204
chrome:1658109204:1658109210
$ aos tab open "data:text/html,<title>aos-bg-test</title>bg" --app=Chrome --window=1658109204
chrome:1658109204:1658109212
$ aos tab open --app=ghostty --window=tab-group-8039faee0 --cwd=/usr --command="echo opened-by-aos-tab"
ghostty:tab-group-8039faee0:tab-802a73a00
  • --window takes an aos window id, the app’s own id, or any tab id in that window. Without it the tab goes into the front window.
  • --new-window opens a window instead.
  • Background is the default. --focus raises the window and shows the new tab; --background is still accepted and does nothing extra. On Windows a tab cannot be opened in the background, so tab open there needs --focus. Exception: with --new-window, Chrome-family browsers come to the front when the window is created, and scripting cannot prevent that.
  • In a terminal, --command runs once and the tab stays open with your normal shell after it.

No focus needed: the terminal receives the text directly, so the person can keep working in another window.

Terminal window
$ aos tab send --id=ghostty:tab-group-8039faee0:tab-802a73a00 --text="echo sent-by-aos"
$ aos tab send --id=ghostty:tab-group-8039faee0:tab-802a73a00 --key=enter
$ aos tab send --id=iterm:22758:2 --key=ctrl+c
$ aos tab send --id=chrome:1658109204:1658109205 --text=hi
aos: Google Chrome tabs cannot receive input from aos: a browser tab has no input channel; focus it and use `aos key` / `aos type`

One tab at a time, never the whole window, and never a close that would stop on a confirmation prompt.

Terminal window
$ aos tab close --id=chrome:1658109204:1658109210
closed chrome:1658109204:1658109210 Example Domains
$ aos tab close --title=aos-bg-test --app=chrome
closed chrome:1658109204:1658109212 aos-bg-test

If the flags match more than one tab, close (and send) refuse with exit 4 and list the candidates; name one with --id or --exact. Index ids (Safari, iTerm2, Terminal) shift when an earlier tab closes, so pass --expect-title to make sure the id still points at the tab you listed:

Terminal window
$ aos tab close --id=safari:22718:2 --expect-title=Example
closed safari:22718:2 Example Domains

tab read prints the page of a browser tab as markdown, built from the accessibility tree (only the page, not the toolbar). Buttons, links and fields get a short ref:

Terminal window
$ aos tab read --id=chrome:1658109971:1658109972
# Tab Test Page
Static intro text.
Message
[e6] Message (textarea, empty) [e7] Send (button) [e8] Docs link (link)
- first item
- sent: hello

--json gives the same markdown plus an elements array (ref, role, label, value). Act on an element by its ref, or by its label:

Terminal window
$ aos tab type --id=chrome:1658109971:1658109972 --element=e6 --text="hi aos" --enter
typed into e6 Message (textarea, empty)
$ aos tab click --id=chrome:1658109971:1658109972 --find=Send --role=button
clicked e7 Send (button)
  • --into (type) and --find (click) match the label, placeholder, title or description: exact matches first, then substrings. --exact turns substrings off. When several elements match, the command refuses with exit 4 and lists them with their refs; pick one with --element or --nth.
  • A ref names an element, not a position. tab read remembers what each ref stood for: the role and label, the HTML id when the page set one, the nearest text before it (so each message’s “Reply” button is its own), and its rounded position. --element finds that element on the page as it is now, so messages arriving above a chat box between the read and the type do not break the ref. aos never picks “the second Reply” by counting, because in a scrolling list where one item left and another arrived, counting lands on a neighbour. When the element is gone it exits 3. When several elements still fit, it exits 4 and lists them with their current refs. It does nothing in both cases. Refs also stay the same across reads. Once the textarea is e6 on a page, it stays e6. New elements get numbers never used before on that page, and elements that disappear give up their ref. The memory is kept per tab and URL in the user cache folder. With no read yet, or after the tab moved to another URL, --element refuses (exit 3) until you run tab read again.
  • The frontmost app does not change. A click is an accessibility press, and the mouse does not move. Typing focuses the field through accessibility and posts key events to the browser’s process, so pages that keep their own state (React, Lexical) see real key and input events.
  • Typing is checked as it goes. After focusing the field, aos reads back the browser’s focused element and refuses (exit 3, nothing typed) unless it is that very element. Before every 16 characters and before Enter it checks again that the same element (not just one with the same label) has focus, and that you have not switched to another window of the browser. If the focus moved, it stops and reports how many characters were already sent. Right before typing, it also checks that the tab is still selected and still shows the same title and URL.
  • Typing makes the tab’s window the browser’s key window (inside the browser, without bringing the browser forward). aos first checks which app is in front. If it is not the browser, typing goes ahead. If the browser is the app in front and you are in another of its windows, or aos cannot tell which of its windows has focus, tab type refuses: your next keystroke would land in the tab’s window. Pass --allow-focus to type anyway.
  • A newline in --text is a Return key, which can submit a chat box halfway through. It is refused unless you pass --allow-newline. Use --enter to press Return once at the end. In a textarea, Return adds a new line unless the page handles it.
  • On Windows, an element with no Invoke pattern can only be clicked with the mouse, which raises the window. tab click refuses unless you pass --allow-focus.
  • Page commands never switch tabs or raise windows; tab open is background by default; only tab focus brings a tab forward. Only the selected tab of a window has a page in the accessibility tree, so a page command aimed at a tab its window is not showing is refused (exit 3) with a pointer to aos tab focus. Pass --focus to let that one command switch to the tab; this is the only way a page command switches tabs. tab list is read-only: it reads titles and URLs and never activates, selects or raises anything.
  • Chrome and other Chromium browsers show nothing below the toolbar until a client asks for it. When the page is missing, aos turns on AXEnhancedUserInterface for that browser process only, and turns it off again when the command ends (watch tab: when the watch ends, Ctrl-C included). While it is on, that browser’s window animations can be slower.

Every page command (tab read, tab type, tab click, watch tab) names its tab with --id, or with --url= / --title= (a substring, narrowed with --app). When several tabs match, it exits 4 and lists them with their ids. It never types into a guessed tab:

$ aos watch tab --url=web.whatsapp.com --match="hello"
$ aos tab type --url=web.whatsapp.com --into="Type a message" --text="on my way" --enter

watch tab re-reads the page and prints the lines that were not there before. The text already on the page when the watch starts is the baseline:

Terminal window
$ aos watch tab --id=chrome:1658109971:1658109972 --match=sent --timeout=1m
{"event":"tab","at":"2026-10-18T10:36:23+05:30","seq":1,"tab":"chrome:1658109971:1658109972","added":["sent:","tick line 23 at 10:36:03"]}
  • With --match, it exits 0 as soon as matching text appears, or exits 3 on --timeout. Use this to wait for a reply or a build result.
  • New text is counted, not compared as a set. A page whose lines change order adds nothing. A second “ok” is news. Digits are ignored when lines are compared, so a clock or “3 minutes ago” that ticks over is not reported.
  • Field contents are left out, so typing into a box is not reported as new text.
  • If someone switches the window to another tab, the watch waits until the tab is selected again. It does not switch back.
  • A browser slows timers in hidden windows, so a page in a covered window can change only about once a minute.
  • The interval is 1 s by default and cannot be shorter: every read walks the whole page.
  • Navigating the tab to another page is not special. The new page’s lines come out as added text.
  • If the tab closes, the watch exits 3.
macOS Windows Linux
tab read, watch tab Chrome family, Safari (accessibility) Edge, Chrome (UI Automation) not yet (exit 2)
tab click AXPress UIA Invoke, else a click at the element’s centre not yet
tab type AXFocused + keys posted to the browser process UIA SetFocus + keys posted to the window (not tested live yet) not yet
app list focus open send close
Chrome, Edge, Brave, Vivaldi, Chromium title, URL yes URL, new window, background no yes
Safari title, URL yes URL, new window, background no yes
Ghostty 1.3+ title, folder, panes tab and pane folder, command text, keys yes
iTerm2 title, folder, panes tab and pane folder, command text, enter, ctrl+letter yes
Terminal.app title yes new window only text (run as a command) a window’s only tab, when idle
any other app (macOS) title, from the accessibility tree yes no no cmd+w, best-effort
any app (Windows) title, from UI Automation yes Edge, Chrome, Brave, Windows Terminal no ctrl+w (browsers, Notepad), ctrl+shift+w (Windows Terminal), best-effort

Accessibility close is best-effort: aos re-checks that the tab’s window is in front immediately before pressing the shortcut, and reports success only when the tab count dropped. Apps whose shortcut it does not know are refused. On Windows no URL or folder goes through cmd.exe; --command for Windows Terminal is a shell command by design.

Linux is not supported yet; aos tab exits 2 there.

Symptom Fix
macOS blocked aos from controlling Google Chrome (Automation permission) macOS asks once per app. If it was denied, turn it on in System Settings > Privacy & Security > Automation, or run tccutil reset AppleEvents and try again to get the prompt back.
aos tab: Google Chrome: timed out on stderr The app took longer than 1.5 s to answer, usually a beachballing browser. The other apps’ tabs still print.
… is gone (list again with aos tab list) The tab or window closed since you listed it. Index ids (Safari, iTerm2, Terminal) also shift when an earlier tab closes.
A Ghostty or Terminal window’s aos id changed macOS makes each native tab its own window. Use native_window or a tab id with --window.