edit_text_file
This directory contains the files that implement the configuration editing utility for the Talon user community config. This utility allows users to quickly open and edit frequently used system, configuration, and vocabulary files with voice commands.
How It Works
The utility operates by mapping verbal aliases to file paths, which are then resolved relative to the user's Talon community repository and opened in an OS-appropriate default text editor.
The process is broken down into three main components:
-
Mapping Configuration: The list edit_text_file_list.talon-list maps spoken aliases to specific file paths. For example, saying "additional words" maps to
core/vocabulary/vocabulary.talon-list, while saying "abbreviations" maps tosettings/abbreviations.csv. -
Voice Commands: The syntax for trigger commands is defined in edit_text_file.talon. Speaking the command
customize <file_alias>triggers the underlying action. For instance, speaking "customize additional words" will execute the custom editing action on the designated vocabulary list. The command also issues a minor delay (sleep(500ms)) followed byedit.file_end()to automatically place the cursor at the end of the file, allowing the user to immediately start writing. -
Core Logic & OS Compatibility: The edit_text_file.py script handles the heavy lifting of resolving paths and launching external text editors. It contains:
- Path Resolution: Relative paths defined in the Talon list are automatically resolved against the root directory of the repository.
- Windows Support: Uses
os.startfile(path, "edit")to open files using the file's default editor association. If "edit" fails, it falls back to "open". - macOS Support: Uses
/usr/bin/open -twithin a subprocess to invoke the system's default GUI text editor. - Linux Support: Uses
xdg-opento launch the registered application for the file's MIME type.