Skip to content

koenbok/FocusBrowserTab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

focus-browser-tab

Focus an existing browser tab in the macOS default browser, or open it if the tab is missing.

./focus-browser-tab https://mail.google.com/

This repo is intentionally just a script. No npm package, no install step beyond putting the file somewhere in your PATH.

Install

Download the script:

curl -fsSL https://raw.githubusercontent.com/koenbok/FocusBrowserTab/main/focus-browser-tab -o focus-browser-tab
chmod +x focus-browser-tab

Install it globally:

sudo mv focus-browser-tab /usr/local/bin/focus-browser-tab

Then use it like this:

focus-browser-tab https://mail.google.com/
focus-browser-tab mail.google.com
focus-browser-tab --app "Google Chrome Beta" https://linear.app/
FOCUS_BROWSER_TAB_APP="Arc" focus-browser-tab https://linear.app/

What it does

  • Defaults to the macOS default browser for https: URLs
  • Accepts an explicit browser via --app or FOCUS_BROWSER_TAB_APP
  • Normalizes a host like mail.google.com to https://mail.google.com
  • If the browser is not already running, opens the target URL
  • If the browser is running, scans existing tabs via AppleScript
  • Focuses the first matching tab by host and path prefix
  • Opens a new tab only when no existing tab matches

Matching behavior

  • Hosts match exactly or by subdomain
  • Paths match exactly or by prefix
  • URL fragments are ignored
  • Query strings are ignored for matching

Examples:

  • https://mail.google.com/ matches https://mail.google.com/mail/u/0/#inbox
  • https://app.slack.com/client matches https://app.slack.com/client/T123/C456

Requirements

  • macOS
  • macOS default browser should expose a Chrome-compatible AppleScript dictionary
  • Or pass --app to target a specific scriptable Chromium-based browser

Notes

  • The script uses osascript and is macOS-only.
  • By default the browser target is resolved from macOS via NSWorkspace.
  • Some browsers expose similar AppleScript dictionaries, but compatibility is not guaranteed.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages