By Alvin Alexander. Last updated: August 12, 2024
Here’s a little macOS shell script I created to text myself a “mindfulness reminder” at random times during the day. The file named quotes_sorted.txt contains about 300 mindfulness-related quotes, and this sends me a text message with a random quote.
#!/bin/bash DIR="/Users/al/Projects/foo/bar" cd $DIR quotes_file="quotes_sorted.txt" current_quote_file="current_quote.txt" # -------------------------------------------- # first, get a random quote from the file, and # put that in our shared file. then schedule # the job using 'at'. # -------------------------------------------- # get the total number of lines total_lines=$(wc -l < "$quotes_file") # generate a random line number random_line_num=$(jot -r 1 1 $total_lines) # get the random quote from the file random_quote=`awk "NR == $random_line_num" "$quotes_file"` # put that quote in our shared file echo "MESSAGE=\"$random_quote\"" > $current_quote_file # schedule the text message to be sent using 'at' minutes_from_now=$(jot -r 1 10 170) echo "sh ${DIR}/SendTextMsgUsingPhoneNumber.sh" | at now + $minutes_from_now minutes
The complete solution uses this script, the Mac “send myself a text message” script I shared previously, and knowledge of macOS launchd jobs.