-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimessage.py
31 lines (24 loc) · 1.24 KB
/
imessage.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
25
26
27
28
29
30
31
import subprocess
from typing import List
def send_imessage(reciever_contact: str, message: str):
"""
Sends an iMessage to a contact with a specified message.
The contact can be either a phone number or email address.
Note: using triple quote strings will have awkward formatting when the message is sent.
:param str reciever_contact: the contact of the person recieving the message
:param str message: the message being sent to the reciever
"""
res = subprocess.run(["osascript", "imessage.scpt", reciever_contact,
message], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode != 0:
assert res.returncode != 0, res.stderr.decode('utf-8')
def send_group_imessage(reciever_contacts: List[str], message: str):
"""
Sends a iMessage to multiple recievers with a specified message.
The contact can be either a phone number or email address.
Note: using triple quote strings will have awkward formatting when the message is sent.
:param List[str] reciever_contacts: a list of contacts for the recievers of the message
:param str message: the message being sent to the recievers
"""
for contact in reciever_contacts:
send_imessage(contact, message)