forked from anonfunc/talon-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
switcher.py
45 lines (34 loc) · 967 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
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")
ctx.keymap({"focus {switcher.apps}": switch_app})
def update_lists():
global apps
new = {}
for app in ui.apps():
if 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
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_launch", "app_close", "win_open", "win_close"):
update_lists()
ui.register("", ui_event)
update_lists()