DEV Community

Cover image for Send Multiple Messages through the Terminal with the iMessage App!
Andres Haro
Andres Haro

Posted on

Send Multiple Messages through the Terminal with the iMessage App!

If you would like to learn a quick and fun trick, you will need to do the following:

  • Get an AppleScript to be able to open the iMessage app:
on run {targetBuddyPhone, targetMessage}
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy targetBuddyPhone of targetService
        send targetMessage to targetBuddy
        send targetMessage to targetBuddy
        say targetMessage
    end tell
end run

Enter fullscreen mode Exit fullscreen mode
  • Create a TXT file that will have some lines of text

  • Create a new Python file: In this python file, you will have to use two different libraries OS, & Config


import os
import config

def get_words(file_path):
    with open(file_path, 'r') as f:
        text = f.readlines()[0]
        words = text.split()
    return words

def get_lines(file_path):
    with open(file_path, 'r') as f:
        text = f.readlines()
    return text

def 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)

Enter fullscreen mode Exit fullscreen mode

After that, you will have to run the script inside the terminal.


python3 main.py

Enter fullscreen mode Exit fullscreen mode

Look at my GitHub repository:

Send Message - Repository

Top comments (0)