Send Multiple Messages through the Terminal with the iMessage App!
Looking at some videos at TikTok, I found a girl that sent multiple messages to his/her partner with a python script. For the same reason, I decided to do it, and explain it in here to make sure everybody can do the same thing….
The first step:
You will need to build an Apple Script that will allow your mac to open the iMessage app to make sure you we will allow to open this app and to make sure we can see the messages that we are sending..
on run {targetBuddyPhone, targetMessage}tell application "Messages"set targetService to 1st service whose service type = iMessageset targetBuddy to buddy targetBuddyPhone of targetServicesend targetMessage to targetBuddysend targetMessage to targetBuddysay targetMessageend tellend run
If you would like to undertand this part:
- Save the following script as
sendMessage.applescript
(Note: make sure to choose the Text option). - Execute it by running:
osascript sendMessage.applescript 1235551234 "Hello there!"
. - This will send an iMessage to the phone number 123–555–1234 containing the text “Hello there!”.
Now, you will need to create a TXT file that will contain the text that you would like to send:
After that, you will be creating the python file and a python script: In this ocassion, I will be naming the file as main.py.
import osimport configdef get_words(file_path):with open(file_path, 'r') as f:text = f.readlines()[0]words = text.split()return wordsdef get_lines(file_path):with open(file_path, 'r') as f:text = f.readlines()return textdef send_message(phone_number, message):os.system('osascript send.scpt {} "{}"'.format(phone_number, message))if __name__ == '__main__':#words = get_words('ly.txt')#for word in words:#send_message('6197516857', word)text = get_lines('ly.txt')for line in text:send_message('18012321787', line)
Now that you have everything, you will have to run the python file from your terminal:
python3 main.py
Example of the outcome that you should be getting:
Of course Spamming people is not okay, and I don’t recommend that, but I love seeing things that are working. Maybe this can be use as an emergency or to joke with your friends…!
Please let me know if you have any other questions or concerns and I would be more than happy to help you!