Last active
October 10, 2018 16:12
-
-
Save comodoro/922717a4eedd4a5691ae42b41e3d349f to your computer and use it in GitHub Desktop.
Bring me for Caster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Caster": "https://caster.readthedocs.io/en/latest/", | |
"Dragonfly": "https://dragonfly2.readthedocs.io/en/latest/", | |
"Google": "https://www.google.com", | |
"libraries": "%USERPROFILE%", | |
"my documents": "%USERPROFILE%\\Documents", | |
"my pictures": "%USERPROFILE%\\Pictures", | |
"notepad": "notepad" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import webbrowser | |
import threading | |
from dragonfly import Grammar, Choice, Function, Dictation | |
from caster.lib import control, context, utilities, settings | |
from caster.lib.dfplus.merge.selfmodrule import SelfModifyingRule | |
from caster.lib.dfplus.state.short import R | |
config = utilities.load_json_file(settings.SETTINGS["paths"]["BRINGME_PATH"]) | |
def reload(): | |
bring_rule.reset(_rebuild_mapping()) | |
#module functions | |
def bring_it(item): | |
''' | |
Currently simply invoke os.startfile. New thread keeps Dragon from crashing. | |
''' | |
threading.Thread(target=os.startfile, args=(item,)).start() | |
def bring_add(launch, key): | |
''' | |
Add current program or highlighted text to bring me | |
''' | |
if launch=="program": | |
path = utilities.get_active_window_path() | |
else: | |
path = context.read_selected_without_altering_clipboard() | |
config[str(key)] = path | |
utilities.save_json_file(config, settings.SETTINGS["paths"]["BRINGME_PATH"]) | |
reload() | |
def bring_remove(key): | |
''' | |
Remove item from bring me | |
''' | |
del config[str(key)] | |
utilities.save_json_file(config, settings.SETTINGS["paths"]["BRINGME_PATH"]) | |
reload() | |
def _rebuild_mapping(): | |
return {key: os.path.expandvars(value) for key, value in config.iteritems()} | |
class BringRule(SelfModifyingRule): | |
pronunciation = "bring me" | |
mapping = { | |
"bring me <item>": | |
R(Function(bring_it), rdescript="Launch preconfigured program, folder or website"), | |
"<launch> to bring me as <key>": | |
R(Function(bring_add), rdescript="Launch preconfigured program, folder or website"), | |
"remove <item> from bring me": | |
R(Function(bring_remove), rdescript="Launch preconfigured program, folder or website"), | |
} | |
extras = [ | |
Choice("item", _rebuild_mapping()), | |
Choice("launch", { | |
"[current] program": "program", | |
"website": "website", | |
"folder": "folder", | |
}), | |
Dictation("key"), | |
] | |
bring_rule = BringRule() | |
# bring_rule.set_merger(control.nexus().merger) | |
control.nexus().merger.add_selfmodrule(bring_rule) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment