forked from thpoll83/PolyKybdHost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacOSInputHelper.py
23 lines (20 loc) · 893 Bytes
/
MacOSInputHelper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import subprocess
import re
lang_re = re.compile(r"^\s*\d+\) (.*)$")
class MacOSInputHelper():
def getLanguages(self):
result = subprocess.run(['languagesetup', '-Localized'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL)
entries = iter(result.stdout.splitlines())
languages = []
for e in entries:
e = str(e, encoding='utf-8')
m = lang_re.match(e);
if (m):
languages.append(m.group(1))
return languages
def setLanguage(self, lang):
result = subprocess.run(['osascript', '-e', f"do shell script \"sudo languagesetup -langspec {lang}\" with administrator privileges"], stdout=subprocess.PIPE)
output = str(result.stdout, encoding='utf-8')
if not output.startswith(u"System Language set to:"):
return output
return ""