Skip to content

Commit

Permalink
New talon sleep-wake script
Browse files Browse the repository at this point in the history
  • Loading branch information
TestPlan committed Oct 16, 2018
1 parent 153a1ad commit 7555208
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 79 deletions.
16 changes: 16 additions & 0 deletions speech_toggle.py
Original file line number Diff line number Diff line change
@@ -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()
158 changes: 79 additions & 79 deletions switcher.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 7555208

Please sign in to comment.