Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code to print out all voice commands in the knausj talon repository,

#Talon Voice Commands Cheatsheet

This is a demo for how to get a cheatsheet of all Talon voice commands.

To recreate what I did:

  1. Have talon installed on your computer following the instructions at
  2. Paste both the and cheatsheet.talon into the user directory of ~/talon. This makes these scripts available to talon.
  3. Open the talon repl and type

This will generate a markdown file in the same directory you put Currently, the markdown file doesn't look very nice because I am misusing markdown so that when I do the next step, I get containers around the html I generate that are easy to select with css selectors. It woud probably be better to just have the python script create html in the first place, or even 4. In a shell, I open pandoc and run the command

> pandoc -s -c cheatsheet.css -f markdown-raw_html -t html -o cheatsheet.html

This command says "create a standalone document (-s) from the markdown document markdown ( -f markdown) to html (-t html) with the css styleshees cheatsheet.css (-c cheatsheet.css)"

And that gets me the output, cheatsheet.html

This creates a wepbate that when you print it, has make a twenty-four page document with every talon command on it, formatted in a way where it is easy to find things, very information-dense, and organized.

body {
column-count: 3
ul {
margin: 0 0 0 0;
padding: 0 0 0 0
overflow: hidden
p {
display: flex;
border: solid black;
margin: 0 0 0 0
padding: 0 0 0 0;
margin: unset
p > * {
flex: 1;
/*! margin: 0 0 0 0; */
align-content: ;
li {
li > p {
border: none;
overflow: hidden;
display: block
from talon import Module, actions, registry
import sys, os
def list_to_markdown_table(file, list_name):
file.write(f"# {list_name} \n\n")
command_list = registry.lists[list_name][0].items()
file.write(f"> command word {list_name} \n\n")
for key, value in command_list:
file.write( "> **" + key + "** *" + value + "*\n>\n")
def write_alphabet(file):
list_to_markdown_table(file, 'user.letter')
def write_numbers(file):
list_to_markdown_table(file, 'user.number_key')
def write_modifiers(file):
list_to_markdown_table(file, 'user.modifier_key')
def write_special(file):
list_to_markdown_table(file, 'user.special_key')
def write_symbol(file):
list_to_markdown_table(file, 'user.symbol_key')
def write_arrow(file):
list_to_markdown_table(file, 'user.arrow_key')
def write_punctuation(file):
list_to_markdown_table(file, 'user.punctuation')
def write_function(file):
list_to_markdown_table(file, 'user.function_key')
def write_formatters(file):
file.write(f"# formatters \n\n")
command_list = registry.lists['user.formatters'][0].items()
file.write("> command word user.formatters \n")
# file.write("|------|-----|\n")
for key, value in command_list:
file.write( "> **"+ key + "** `" + actions.user.formatted_text(f"example of formatting with {key}", key) + "` \n>\n")
def write_context_commands(file, commands):
# write out each command and it's implementation
for key in commands:
rule = commands[key].rule.rule
implementation = commands[key].target.code.replace("\n","\n\t\t")
except Exception:
file.write("\n - **" + rule + "** `" + implementation + "`\n")
def pretty_print_context_name(file, name):
## The logic here is intended to only print from talon files that have actual voice commands.
splits = name.split(".")
index = -1
os = ""
if "mac" in name:
os = "mac"
if "win" in name:
os = "win"
if "linux" in name:
os = "linux"
if "talon" in splits[index]:
index = -2
short_name = splits[index].replace("_", " ")
short_name = splits[index].replace("_", " ")
if "mac" == short_name or "win" == short_name or "linux" == short_name:
index = index - 1
short_name = splits[index].replace("_", " ")
file.write("\n\n\n" + "# " + os + " " + short_name + "\n\n")
mod = Module()
class user_actions:
def cheatsheet():
"""Print out a sheet of talon commands"""
#open file
this_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(this_dir, '')
file = open(file_path,"w")
#print out all the commands in all of the contexts
list_of_contexts = registry.contexts.items()
for key, value in list_of_contexts:
commands= value.commands #Get all the commands from a context
if len(commands) > 0:
pretty_print_context_name(file, key)
print cheatsheet: user.cheatsheet()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment