Created
October 11, 2019 18:44
-
-
Save shanecowherd/c74928754839e28261ab2c46577d4283 to your computer and use it in GitHub Desktop.
Bash script to automate sending email from Mail.app using AppleScript. (For debugging)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Generate a random text email and send it to [email protected] | |
# Used for testing email apps when you need a lot of messages in a test account. | |
# Configure the script in this section. | |
NUMBER_OF_MESSAGES=10 | |
WORDS_IN_MESSAGE=10 | |
[email protected] | |
WORDFILE=/usr/share/dict/words | |
# using cat means wc outputs only a number, not number followed by filename | |
LINECOUNT=$(cat $WORDFILE | wc -l); | |
until [ $NUMBER_OF_MESSAGES -lt 1 ]; do | |
let NUMBER_OF_MESSAGES-=1 | |
MESSAGE_WORDS="" | |
# Get random line numbers in the word file. | |
RANDOM_NUMBER_LIST=`jot -w %d -n -r -p 1 $WORDS_IN_MESSAGE 1 $LINECOUNT` | |
echo $RANDOM_NUMBER_LIST | |
for RANDWORDINDEX in $RANDOM_NUMBER_LIST | |
do | |
MESSAGE_WORDS="$MESSAGE_WORDS `sed -n "$RANDWORDINDEX p" $WORDFILE;`" | |
done | |
echo Words: $MESSAGE_WORDS | |
subjectRand=`jot -w %d -n -r -p 1 1 1 $LINECOUNT` | |
SUBJECT=`sed -n "$subjectRand p" $WORDFILE;` | |
echo Subject: $SUBJECT | |
osascript -e " | |
tell application \"Mail\" | |
set newMessage to make new outgoing message with properties {visible:true, subject:\"Random: $SUBJECT\", content:\"$MESSAGE_WORDS\"} | |
tell newMessage to make new to recipient at end of every to recipient with properties {address:\"$RECIPIENT\"} | |
send newMessage | |
end tell | |
" | |
sleep 2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment