browser
This directory defines standardized cross-platform voice commands and programmatic actions for controlling web browsers using the Talon voice recognition system. By activating the browser tag, users gain access to a unified set of spoken commands that function seamlessly across different browsers and operating systems.
Voice Commands
The browser.talon file defines the voice command interface. When the browser tag is active, it automatically enables several helper tags to manage input fields and page movement:
user.addressuser.finduser.navigation
This file maps spoken voice commands directly to abstract Python actions. Key capabilities include:
- Page Controls: Reloading pages ("refresh it", "refresh it hard"), going home ("go home"), or opening incognito windows ("go private").
- Bookmark Management: Adding bookmarks ("bookmark it", "bookmark tabs") and opening the bookmarks library ("bookmark show") or bookmark bar ("bookmark bar [show]").
- Browser Utilities: Navigating to downloads, extensions, history, developer tools, and cache-clearing dialogs.
Default Platform Implementations
The underlying behavior for these voice commands is implemented in browser.py. This file contains the default class actions (primarily suited for Windows and Linux environments) and defines fallback logic for common browser tasks:
- Fallback URL Parsing: It attempts to safely extract the current URL from the application window's title bar text if no direct API is available.
- Tab Utilities: Handles tab duplication by retrieving the URL from the address bar, opening a new tab, and pasting the retrieved address. It also implements cross-platform tab navigation (e.g., using
ctrl-[1-9]for Windows/Linux oralt-[1-9]depending on platform architecture). - Keyboard Shortcuts: Maps abstract calls like
reload(),show_history(), andtoggle_dev_tools()to standard PC hotkeys (e.g.,ctrl-r,ctrl-h, andctrl-shift-i).
macOS-Specific Overrides
Because macOS relies on alternative system shortcuts and offers advanced accessibility APIs, browser_mac.py intercepts and overrides actions when running on macOS (os: mac matches).
- Command Keys: It translates typical control-key shortcuts to Command (
cmd) keys, mapping bookmarks tocmd-d, address bar focus tocmd-l, and page reloads tocmd-r. - Robust URL Extraction: Rather than parsing the window title, the macOS implementation queries the operating system's UI accessibility tree. It searches for objects with the
AXWebArearole to extract theAXURLattribute directly from Chromium and Firefox-based browsers. If that fails, it falls back to application-scripting boundaries (appscript) to ask the browser's active tab for its URL.