Skip to content

are_you_sure

This plugin provides a safety mechanism for requiring user confirmation before executing potentially destructive actions—such as shutting down the computer, closing important applications, or stopping the Talon process.

It accomplishes this by rendering a visual confirmation dialog on the screen and dynamically activating specific voice commands that allow the user to confirm or cancel the action.

How It Works

The confirmation system is split into a Python backend that manages state and UI rendering, and a Talon file that defines the voice commands.

  1. Initiation: A separate Talon script or Python function triggers a confirmation flow by calling the action user.are_you_sure_set_on_confirmation_action(message, on_confirmation, on_cancel).
  2. State Transition: The state-management class ConfirmationState in are_you_sure.py stores the confirmation message and the execution callbacks. It then dynamically appends the user.are_you_sure tag to its custom context and opens an interactive GUI at the top of the screen (y=0).
  3. Voice Command Activation: Because the user.are_you_sure tag is now active, Talon enables the voice commands defined in are_you_sure.talon.
  4. Resolution: The user can either say a command or click one of the GUI buttons.
    • Saying "yes I am sure" or clicking "Yes I am sure" fires user.are_you_sure_confirm(), which executes the on_confirmation callback.
    • Saying "cancel" or clicking "Cancel" fires user.are_you_sure_cancel(), which runs the optional on_cancel callback.
  5. Teardown: After resolution, the state is cleared, the overlay is hidden, and the user.are_you_sure tag is removed, deactivating the confirmation voice commands to prevent accidental triggers later.

Component Files

are_you_sure.py

This file defines the core architecture of the confirmation prompt:

  • ConfirmationState: A state-machine class that tracks the registered callbacks, handles context tagging, and manages cleaning up state after an action is resolved.
  • gui(gui: imgui.GUI): An overlay drawn using Talon's built-in Immediate Mode GUI (imgui) module. It displays the custom message and provides buttons for mouse-based interaction.
  • Talon Actions:
    • are_you_sure_set_on_confirmation_action(message: str, on_confirmation: Callable, on_cancel: Callable = None): The entrypoint action used by other scripts to register a confirmation requirement.
    • are_you_sure_confirm(): Programmatically triggers the confirmation callback and resets the state.
    • are_you_sure_cancel(): Programmatically triggers the cancellation callback and resets the state.

are_you_sure.talon

This file defines the voice interface for the confirmation dialog. It is scoped strictly to the user.are_you_sure tag:

tag: user.are_you_sure
-

yes I am sure: user.are_you_sure_confirm()
cancel: user.are_you_sure_cancel()

By constraining these commands to the user.are_you_sure tag, the words "yes I am sure" and "cancel" will not trigger accidental confirmation events during normal dictation or operations.

Usage Example

For a detailed example of how to implement this in your own custom scripts, please refer to the README.md. It outlines how to define a confirmation test using a custom Python function alongside a corresponding voice command.