mycroft-run-script/__init__.py

38 lines
1.1 KiB
Python
Raw Normal View History

2022-02-08 14:29:23 -06:00
import os
2022-02-08 12:42:13 -06:00
from mycroft import MycroftSkill, intent_handler
class RunScriptSkill(MycroftSkill):
def __init__(self):
super().__init__()
2022-02-08 14:29:23 -06:00
self.script_dir = None
self.scripts = []
2022-02-08 12:42:13 -06:00
def initialize(self):
2022-02-08 14:10:12 -06:00
self.settings_change_callback = self.on_settings_changed
self.on_settings_changed()
def on_settings_changed(self):
2022-02-08 15:16:15 -06:00
self.script_dir = self.settings.get('script_dir', os.path.expanduser("~/scripts"))
2022-02-08 14:29:23 -06:00
self.read_scripts_dir()
2022-02-08 14:10:12 -06:00
2022-02-08 14:51:15 -06:00
def read_scripts_dir(self):
2022-02-08 15:22:26 -06:00
if self.script_dir and os.path.isdir(self.script_dir):
self.scripts = os.listdir(self.script_dir)
2022-02-08 14:29:23 -06:00
else:
self.log.critical("The script_dir directory does not exist or can't be read")
self.scripts = []
2022-02-08 12:42:13 -06:00
2022-02-08 13:47:56 -06:00
@intent_handler('RunScript.intent')
def handle_run_script_intent(self, msg=None):
script = msg.data.get('script', None)
2022-02-08 14:29:23 -06:00
if script in self.scripts:
self.speak_dialog('Running', {'script': script})
else:
self.speak_dialog('NotFound', {'script': script})
2022-02-08 12:42:13 -06:00
def stop(self):
pass
def create_skill():
return RunScriptSkill()