forked from tabrat/talon_user
-
Notifications
You must be signed in to change notification settings - Fork 1
/
switcher.py
46 lines (35 loc) · 932 Bytes
/
switcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from talon.voice import Word, Context, Key, Rep, Str, press
from talon import ui
apps = {}
def switch_app(m):
name = str(m._words[1])
full = apps.get(name)
if not full:
return
for app in ui.apps():
if app.name == full:
app.focus()
break
ctx = Context('switcher')
keymap = {
'focus {switcher.apps}': switch_app,
}
ctx.keymap(keymap)
def update_lists():
global apps
new = {}
for app in ui.apps():
words = app.name.split(' ')
for word in words:
if word and not word in new:
new[word] = app.name
new[app.name] = app.name
if set(new.keys()) == set(apps.keys()):
return
ctx.set_list('apps', new.keys())
apps = new
def ui_event(event, arg):
if event in ('app_activate', 'app_deactivate', 'app_launch', 'app_close'):
update_lists()
ui.register('', ui_event)
update_lists()