-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal.py
More file actions
36 lines (32 loc) · 1.23 KB
/
terminal.py
File metadata and controls
36 lines (32 loc) · 1.23 KB
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
28
29
30
31
32
33
34
35
36
import subprocess
import os
#to run messages thru terminal:
def removeQuotes(s):
s = str(s)
s = s.replace("'","")
s = s.replace('"',"")
s = s.replace("`","")
s = s.strip("'").strip("`").strip('"')
return s
def term(message,sender,iMessageEmail):
response = ""
p = subprocess.Popen(message[1:],shell=True) #get output of command
stdout, stderr = p.communicate()
if(stdout):
try:
response = stdout.decode('ascii') # [-1] excludes the return character
except:
response = "There was an error."
else:
try:
response = stderr.decode('ascii')
except:
response = "There was an error."
#print("lets go")
if (response != ""): #if there is output, then send it back. terminal style
response = removeQuotes(response)
if(is_Imessage == 0):
response2 = 'osascript -e \'tell application "Messages" \n send \"' + response + '\" to buddy "{}" of service "SMS" \n end tell\''.format(sender)
else:
response2 = 'osascript -e \'tell application "Messages" \n send \"' + response + '\" to buddy "{}" of service "E:{}" \n end tell\''.format(sender,iMessageEmail)
os.system(response2)