Skip to content

Instantly share code, notes, and snippets.

@marcinantkiewicz
Created March 22, 2026 18:55
Show Gist options
  • Select an option

  • Save marcinantkiewicz/cff880e7dc0c7868be05c06c28b96925 to your computer and use it in GitHub Desktop.

Select an option

Save marcinantkiewicz/cff880e7dc0c7868be05c06c28b96925 to your computer and use it in GitHub Desktop.
OMG, chrome-cli

chrome-cli - a fantastic tool using applescript to provide basic control over chrome. For reasons, Google did not work with the OS makers to provide a secure os-browser bridge, so allowing os to control browser breaks Chrome's security model - as much as I like this tool all such are insecure. Due to lack of practical ways to secure them.

Sample of the chrome-cli help output

chrome-cli list tablinks  (List tabs' with the link)
chrome-cli close -t <id>  (Close specific tab)
chrome-cli open <url> -w <id>  (Open url in new tab in specific window)
chrome-cli activate -t <id> --focus  (Activate tab and bring its window to front)

the tabs are listed with chrome window like [window_id:tab_id]:

[1041679458:1041680768] title: prasmussen/chrome-cli: Control Google Chrome from the command line, url: https://github.com/prasmussen/chrome-cli
[1041679458:1041680770] title: Create a new Gist, url: https://gist.github.com/
[1041679458:1041680773] title: Google Gemini, url: chrome://newtab/

So, to close all hackernews site tabs I split the ids, and keep the 2nd one:

chrome-cli list tablinks |                     \
grep 'https://news.ycombinator.com/item?id=' | \
cut -d ':' -f 2  | cut -d ']' -f 1 |           \
while read tabid; do                           \
  echo "closing $tabid";                       \
  chrome-cli close -t $tabid;                  \
done

or chrome-cli close -t 1041680773
to switch focus chrome-cli activate -t 1041680773 --focus

Note; this requires allowing the terminal Accessibility controls in OSX Privacy & Security. Not a secure idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment