├── README.md ├── send.scpt ├── send.sh └── sms.txt /README.md: -------------------------------------------------------------------------------- 1 | # Bulk macOS Messages 2 | 3 | It's not currently possible on iOS or macOS to send an SMS message or Apple Message to multiple people individually (as opposed to a group) without creating a new message for each person. This script automates that process on macOS. 4 | 5 | ## How it works 6 | 7 | `send.scpt` is an AppleScript that reads environment variables `recipients` and `message`. It then loops over the list of recipients and tells the Messages app to send the message to each recipient. After looping over the list it renames `sms.txt` to `sms-${current_date}.txt` and creates a blank `sms.txt`. 8 | 9 | `sms.txt` is where the `recipients` phone numbers and the `message` text are defined. 10 | 11 | `send.sh` starts a `tail` process that watches `sms.txt` for changes. If there is text in the file, it attempts to set environment variables for `recipients` and `message`, and then starts the `send.scpt` AppleScript. 12 | 13 | ## Pre-requisites 14 | 15 | * A computer running macOS and an iCloud an account. Tested on macOS 10.13 High Sierra. 16 | * Enable [SMS Forwarding](https://support.apple.com/en-us/HT204681#SMS) if you want to send to non-iOS recipients. 17 | 18 | 19 | ## Setup 20 | 21 | 1. Clone this repository and replace the contents of `sms.txt` with your recipients list and message text. 22 | 1. Update `send.sh` line 4 with the directory where your `sms.txt` file will live. For example, you can point to a Dropbox folder to facilitate triggering a send from your phone or any computer by editing this file. 23 | 1. Make the script executable by running `chmod +x send.sh`. 24 | 1. Run `./send.sh` in a Terminal window. 25 | 1. Verify that the messages were sent by checking the Messages app on your Mac or on an iOS device. 26 | 27 | ## Notes 28 | 29 | * If you want to send a group of messages but don't have the need for triggering a send remotely, or if you're not going to be using the script regularly, you can simply pass environment variables directly into the AppleScript by running `recipients="12345678901 11098765432" message="message here" osascript send.scpt`. This sets the variables for `recipients` and `message` directly, as opposed to reading them in from the `sms.txt` file. `send.sh` is not needed if you're using this method. 30 | * This AppleScript will only send to recipients with whom you have an existing conversation in Messages. 31 | * SMS has a limit of 160 characters, whereas Messages can handle ~20k characters. This script does not enforce character limits. 32 | * The `message` can't contain straight double quotes (" ")—use curly quotes instead (“ ”). Other special characters may cause issues. 33 | * If sending to one recipient fails, the script will exit. Be sure to remove recipients who have been sent the message successfully before running the script again, to avoid sending duplicate messages. 34 | 35 | ## References 36 | 37 | * https://alvinalexander.com/apple/applescript-for-loop-while-loop-examples 38 | * https://hints.macworld.com/article.php?story=20050523140439734 39 | * https://stackoverflow.com/questions/9574089/osx-bash-watch-command -------------------------------------------------------------------------------- /send.scpt: -------------------------------------------------------------------------------- 1 | -- Get environment variables message and recipients 2 | set message to system attribute "message" 3 | set recipients to system attribute "recipients" 4 | 5 | -- Print the list of recipients to the console 6 | log recipients 7 | 8 | tell application "Messages" 9 | -- Get the Messages service of type iMessage 10 | set targetService to 1st service whose service type = iMessage 11 | 12 | -- For each 'recipient' in the list of recipients, set the 'buddy' item 13 | -- then send the text in the 'message' variable to that recipient 14 | repeat with recipient in words of recipients 15 | set recipient to buddy recipient of targetService 16 | send message to recipient 17 | delay 1 18 | end repeat 19 | 20 | end tell 21 | -------------------------------------------------------------------------------- /send.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Watch the file named sms.txt; add a custom directory (like Dropbox or Files) to reference a file outside of the current directory. 4 | directory=. 5 | tail -F ${directory}/sms.txt | while read line; do 6 | 7 | # If the file has a line containing 'recipients' 8 | if echo "$line" | grep -q 'recipients'; then 9 | 10 | # Set sms.txt 'recipients' and 'message' as env vars, Run AppleScript 11 | source ${directory}/sms.txt 12 | echo "sending" 13 | message=$message recipients=$recipients osascript send.scpt 14 | 15 | # Move sms.txt to a new file called "sent-${current_date}.txt" 16 | current_date="`date +%Y%m%d%H%M`"; 17 | mv ${directory}/sms.txt ${directory}/${current_date}-sent.txt 18 | 19 | # Create a blank sms.txt file, which can be updated to send a new batch 20 | touch ${directory}/sms.txt 21 | 22 | fi 23 | 24 | done 25 | 26 | -------------------------------------------------------------------------------- /sms.txt: -------------------------------------------------------------------------------- 1 | recipients="1234567890 19876543210" 2 | message="Testing" 3 | --------------------------------------------------------------------------------