websites_and_search_engines
This directory provides voice-controlled capabilities for opening websites and searching the web using pre-configured search engines. It abstracts web browser navigation into a set of fast, global voice commands.
Architecture and Workflow
The system relies on a clean separation between Talon action definitions, voice command grammar, and configurable URL/search engine datasets.
Here is how the components work together:
- Defining the Infrastructure: websites_and_search_engines.py sets up the Talon module and registers two lists:
user.websiteanduser.search_engine. It also defines custom actions for opening URLs (open_url) and executing formatted search engine queries (search_with_search_engine) using Python's standardwebbrowserlibrary. - Data Storage (Lists):
- website.talon-list maps spoken names (e.g., "github", "talon wiki") to their corresponding URLs.
- search_engine.talon-list maps spoken names to search query URLs containing a
%splaceholder (e.g., "google" maps tohttps://www.google.com/search?q=%s).
- Voice Commands: websites_and_search_engines.talon defines the voice syntax that triggers these actions.
Command Usage and Examples
Direct Navigation
The "open" commands let you navigate directly to defined sites or target URLs extracted from your environment:
- "open <website>" (e.g., "open github"): Looks up the URL in website.talon-list and opens it in your default web browser.
- "open that": Extracts the currently highlighted/selected text and attempts to open it as a URL.
- "open paste": Reads the clipboard contents and opens it as a URL.
Performing Searches
The search syntax supports searching for arbitrary spoken text, selected text, or clipboard contents:
- "<search_engine> hunt <text>" (e.g., "google hunt talon voice"): Executes a search for the spoken phrase. Python's
urllib.parse.quote_plusis used to safely URL-encode the text and substitute it into the search template's%splaceholder. - "<search_engine> (that | this)" (e.g., "wiki that"): Searches the designated engine using your currently selected text.
- "<search_engine> paste" (e.g., "amazon paste"): Searches the designated engine using the text currently stored in your clipboard.
Browser-Specific Captures
In addition to global commands, websites_and_search_engines.py defines a context-specific capture rule:
ctx_browser = Context()
ctx_browser.matches = r"""
tag: browser
"""
When a web browser is active, this context exposes a user.address capture that resolves spoken names from website.talon-list into clean URL strings. This allows other browser-specific voice files in the community repository to easily reuse the configured list of websites for tasks like address-bar navigation.