-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdragon.py
57 lines (50 loc) · 1.78 KB
/
dragon.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
from talon.engine import engine
from talon.voice import Context, Str, press
from talon import applescript, ctrl
from .misc.speech_toggle import set_voice_type, VoiceType
from .utils import delay
context = Context("dragon")
def open_dragon_menubar():
old = ctrl.mouse_pos()
x = applescript.run("""
tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
set AppleScript's text item delimiters to ", "
position as string
end tell
""")
x, y = map(int, x.split(", "))
ctrl.mouse(x+5, y+5)
ctrl.mouse_click()
ctrl.mouse(*old)
def open_dragonpad():
open_dragon_menubar()
applescript.run("""
tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
click menu item "Help" of menu 1
click menu item "DragonPad" of menu of menu item "Help" of menu 1
end tell
""")
# def toggle_status_win(val):
# open_dragon_menubar()
# applescript.run(f"""
# tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
# click (menu item where its name ends with "Status Window") of menu 1
# end tell
# """)
def set_status_win(val):
open_dragon_menubar()
command = "Show Status Window" if val else "Hide Status Window"
applescript.run(f"""
tell application "System Events" to tell process "Dragon" to tell (menu bar item 1 of menu bar 2)
click menu item "{command}" of menu 1
end tell
""")
context.keymap(
{
"hide status": lambda m: set_status_win(False),
"show status": lambda m: set_status_win(True),
"dragon pad": lambda m: open_dragonpad(),
# "toggle status": lambda m: toggle_status_win(),
}
)
context.load()