diff --git a/speech_toggle.py b/speech_toggle.py new file mode 100644 index 0000000..849fee6 --- /dev/null +++ b/speech_toggle.py @@ -0,0 +1,16 @@ +# From https://github.com/talonvoice/examples +from talon.voice import Context, ContextGroup +from talon.engine import engine +from talon_plugins import speech + +sleep_group = ContextGroup('sleepy') +sleepy = Context('sleepy', group=sleep_group) + +sleepy.keymap({ + 'talon sleep': lambda m: speech.set_enabled(False), + 'talon wake': lambda m: speech.set_enabled(True), + + 'dragon mode': [lambda m: speech.set_enabled(False), lambda m: engine.mimic('wake up'.split())], + 'talon mode': [lambda m: speech.set_enabled(True), lambda m: engine.mimic('go to sleep'.split())], +}) +sleep_group.load() diff --git a/switcher.py b/switcher.py index 94f9c2c..e41f67a 100644 --- a/switcher.py +++ b/switcher.py @@ -1,79 +1,79 @@ -from talon.voice import Word, Context, Key, Rep, Str, press -from talon import ui -import time -import os - -running = {} -launch = {} - - -def switch_app(m): - name = str(m['switcher.running'][0]) - full = running.get(name) - if not full: return - for app in ui.apps(): - if app.name == full: - app.focus() - # TODO: replace sleep with a check to see when it is in foreground - time.sleep(0.25) - break - - -def launch_app(m): - name = str(m['switcher.launch'][0]) - path = launch.get(name) - if path: - ui.launch(path=path) - - -ctx = Context('switcher') -ctx.keymap({ - 'focus {switcher.running}': switch_app, - 'launch {switcher.launch}': launch_app, -}) - -applications = ( - '/Applications', - '/Applications/Photoshop', - '/Applications/Utilities', - '/Applications/JetBrains/apps/WebStorm', -) - -def update_lists(): - global running - global launch - new = {} - for app in ui.apps(): - if app.background and not app.windows(): - continue - words = app.name.split(' ') - for word in words: - if word and not word in new: - new[word] = app.name - new[app.name] = app.name - running = new - ctx.set_list('running', running.keys()) - - new = {} - for base in applications: - for name in os.listdir(base): - path = os.path.join(base, name) - name = name.rsplit('.', 1)[0] - new[name] = path - words = name.split(' ') - for word in words: - if word and word not in new: - if len(name) > 6 and len(word) < 3: - continue - new[word] = path - launch = new - ctx.set_list('launch', launch.keys()) - - -def ui_event(event, arg): - if event in ('app_activate', 'app_launch', 'app_close', 'win_open', 'win_close'): - update_lists() - - -ui.register('', ui_event) -update_lists() +# from talon.voice import Word, Context, Key, Rep, Str, press +# from talon import ui +# import time +# import os +# +# running = {} +# launch = {} +# +# +# def switch_app(m): +# name = str(m['switcher.running'][0]) +# full = running.get(name) +# if not full: return +# for app in ui.apps(): +# if app.name == full: +# app.focus() +# # TODO: replace sleep with a check to see when it is in foreground +# time.sleep(0.25) +# break +# +# +# def launch_app(m): +# name = str(m['switcher.launch'][0]) +# path = launch.get(name) +# if path: +# ui.launch(path=path) +# +# +# ctx = Context('switcher') +# ctx.keymap({ +# 'focus {switcher.running}': switch_app, +# 'launch {switcher.launch}': launch_app, +# }) +# +# applications = ( +# '/Applications', +# '/Applications/Photoshop', +# '/Applications/Utilities', +# '/Applications/JetBrains/apps/WebStorm', +# ) +# +# def update_lists(): +# global running +# global launch +# new = {} +# for app in ui.apps(): +# if app.background and not app.windows(): +# continue +# words = app.name.split(' ') +# for word in words: +# if word and not word in new: +# new[word] = app.name +# new[app.name] = app.name +# running = new +# ctx.set_list('running', running.keys()) +# +# new = {} +# for base in applications: +# for name in os.listdir(base): +# path = os.path.join(base, name) +# name = name.rsplit('.', 1)[0] +# new[name] = path +# words = name.split(' ') +# for word in words: +# if word and word not in new: +# if len(name) > 6 and len(word) < 3: +# continue +# new[word] = path +# launch = new +# ctx.set_list('launch', launch.keys()) +# +# +# def ui_event(event, arg): +# if event in ('app_activate', 'app_launch', 'app_close', 'win_open', 'win_close'): +# update_lists() +# +# +# ui.register('', ui_event) +# update_lists()