-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathswitcher.py
62 lines (47 loc) · 1.43 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
def short_application(m, app):
m._words = [0, app]
switch_app(m)
ctx = Context('switcher')
keymap = {
'fox {switcher.apps}': switch_app,
'gossip': lambda x: short_application(x, 'Slack'),
'madame': lambda x: short_application(x, 'Atom'),
'termite': lambda x: short_application(x, 'iTerm2'),
'masseuse': lambda x: short_application(x, 'Messages'),
'chromie': lambda x: short_application(x, 'Google Chrome'),
'roman': lambda x: short_application(x, 'R'),
'emacs': lambda x: short_application(x, 'MacVim'),
}
ctx.keymap(keymap)
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()