app_switcher
The community/core/app_switcher
directory contains files that enable users to switch between and launch applications using voice commands. It also includes a basic UI for viewing running applications. The core logic for this functionality resides in app_switcher.py
, with platform-specific overrides for application names defined in CSV files.
The application switching logic is implemented in the app_switcher.py
file, which defines the following:
- Lists: The module defines two lists:
running
, which represents all currently running applications, andlaunch
, which represents all launchable applications. - Overrides: Spoken forms for application names can be overridden via CSV files. These overrides are stored in the
overrides
dictionary. There is also anexcludes
set of app names that should not be included in the running list. - Application Lists: The
get_apps()
function is platform-specific and is responsible for generating the list of launchable applications. On Windows, it uses theshell:AppsFolder
to retrieve all applications, including "modern" apps. On Linux, it parses.desktop
files in common application directories. On MacOS, it lists all.app
directories in common application directories. - Update Functions: The
update_running_list()
function updates the list of running applications, and theupdate_overrides()
function updates the overrides and excludes lists by reading the platform-specific CSV file. Theupdate_launch_list()
function usesget_apps()
to update the list of launchable apps. - Actions: The module defines a variety of actions:
get_running_app(name: str)
retrieves the application object for the running app with the provided name.switcher_focus(name: str)
focuses the application given by the provided name.switcher_focus_app(app: ui.App)
focuses the provided application.switcher_focus_window(window: ui.Window)
focuses the provided window.switcher_launch(path: str)
launches the application at the provided path.switcher_menu()
opens a menu of running apps (platform-specific).switcher_toggle_running()
shows/hides a list of running applications.switcher_hide_running()
hides the list of running applications.
- GUI: The module includes a simple ImGui based GUI to show the running applications with their associated spoken forms.
- Events: The
ui_event
function updates the running list on application launch and close events. - Startup: The
on_ready
function is called when Talon is ready. It initializes the overrides, starts watching the override directory for changes, updates the launch and running lists and registers theui_event
callback function.
The directory also contains three CSV files that define platform-specific spoken form overrides:
* app_name_overrides.linux.csv
* app_name_overrides.windows.csv
* app_name_overrides.mac.csv
These files contain comma-separated values. The first column is the spoken form, and the second column is the application name or .exe
(on Windows). If a line contains only one value, the application specified will be excluded from the running list. These files are used by the update_overrides
function in app_switcher.py
to update the overrides
and excludes
lists.
In summary, the app_switcher
directory provides a robust mechanism for launching and switching between applications using voice commands, with platform-specific adjustments and overrides.