-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSpeakSelectedText.py
24 lines (21 loc) · 1016 Bytes
/
SpeakSelectedText.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
import subprocess
import sublime, sublime_plugin
class SpeakSelectedTextCommand(sublime_plugin.TextCommand):
def run(self, edit):
selections = self.view.sel()
selection = self.view.substr(selections[0])
selection = selection.replace('"', '\\"')
process = subprocess.Popen( "ps aux | grep say | wc -l", shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
processes, error = process.communicate()
processes = processes.strip()
if int(processes) > 2:
subprocess.Popen( "killall say", shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE )
else:
subprocess.Popen( 'say "{0}"'.format(selection), shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE )