-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.py
More file actions
27 lines (25 loc) · 891 Bytes
/
lib.py
File metadata and controls
27 lines (25 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import subprocess
def get_shortcuts():
shortcuts = os.system(f"osascript -e 'tell application \"Shortcuts\" to get name of every shortcut'")
return shortcuts
def use_model(texte, shortcut: str="use_a_model"):
try:
processus = subprocess.run(
["shortcuts", "run", shortcut],
input=str(texte),
text=True,
capture_output=True
)
if processus.returncode == 0:
if processus.stdout.startswith("{\\rtf"):
nettoyage = subprocess.run(
["textutil", "-convert", "txt", "-stdin", "-stdout"],
input=processus.stdout,
text=True,
capture_output=True
)
return nettoyage.stdout.strip()
return processus.stdout.strip()
except Exception as e:
print(e)