DEV Community

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

Posted on

1

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay