Using If Then Else to Respond to Messages

I think that a number of people might find themselves in a situation similar to mine. I have a friend, for now, who insists on disregarding my request to stop texting me with his political views. I work in a family owned business 12 - 14 hours a day 6 - 7 days a week. My friend sits at home all day living on government benefits for his alleged illness. I would like to create a macro that would open unanswered messages from this individual and respond with something like, “Jay a political genius in his own mind has ignored my request to refrain from texting me his political views. I will not see his political pontifications but have created a program that will return his thoughts to him.…” Lest I sound harsh this individual cannot have a rational political discussion. He typically engages in the logical fallacies of name calling, ad hominem attacks, straw man, band wagon, false dilemma and stacking the deck. Not surprisingly he has very few friends.

Right now I am wondering if Control Flow/If Then Else could be used to generate a response to each message this person might send me. So if I received 3 messages overnight I could launch Keyboard Maestro sometime during the day and have it respond to each message instead of just the last one and then close Messages. I just can’t figure out which ‘Conditions’ to use to ‘inform’ KM that I have received a new message from this individual only that needs to be responded to.

Are these email or text messages?
What app are you receiving the messages in?

My first guess is that creating a rule in the app receiving the message would be simplest. You could do this in both Apple Mail and Outlook.

Keyboard Maestro needs a way to be triggered. How would it know when you received these messages?

Thank you JMichaelTX. These are text messages I am receiving through the Messages app on my Mac running El Capitan. When I start my Mac each morning I thought I could check the badge on the Messages icon in the Dock. With this in mind, I’ve set a hot key combination to launch the KM macro. I guess an alternative would be to have KM launch every morning maybe 20 minutes after I started my Mac open Messages, check for new messages from this one individual (as compared to the people I don’t mind receiving messages from) and respond if a new message(s) have been received. My idea is that he will grow tired of sending messages that are not even looked at and eventually stop.

The more I look at what I want to do JMichaelTX the more I think that it will be too difficult. If there were more Message specific actions like with Safari it might not be too hard, at least for me. I was thinking the answer might be in the Control Flow and/or Variables Categories but after going through those for hours I now think this cannot be done. I guess I can fake this by manually responding to these texts using a memorized text string.

Bruce, I think this AppleScript might do the job.
It provides for an immediate auto-reply to specified senders.
Please let me know if you run into any glitches. I have given this limited testing.

###SCRIPT: [MSG] Auto Response Script for Apple
[MSG] Auto Response Script for Apple Messages (AS) (11.4 KB)

VER: 1.0 LAST UPDATE: 2016-04-30


  • Provide an auto-reply to Text Message Senders who are sending you unwanted messages.
  • This is for messages received in the Apple on your Mac.



  1. Mac OS X Yosemite 10.10.5+
  2. Mac Applications
  • Apple


  1. Open in Script Editor
  2. EDIT script to set:
    • Buddy Name (myAnnoyingBuddyName)
    • Msg to reply with (replyMsgAnnoy) when you received msg from Buddy
  3. Compile script
  4. Save to Script folder
    ~/Library/Application Scripts/
    You can open this folder from Preferences:
    General Tab > AppleScript handler
  5. In the Preferences, set the "AppleScript handler" to this script

###Here is the Key Section of the Script
(download complete script above)

--		If you are not sure what your buddy's name is,
--		then set the next property to true to receive a notification 
--		with buddy's name

property showNotify : false -- SET TO true TO ENABLE NOTIFICATION on your Mac

set myAnnoyingBuddyName to "BuddyName" -- as it shows in Messages
set replyMsgAnnoy to "I couldn't care less.  Don't bother me!"

using terms from application "Messages"
  on message received theMessage from theBuddy for theChat
    if showNotify then
      set notificationMessage to name of theBuddy & return & theMessage
      display notification notificationMessage --sound name "Sosumi"
    end if
    if (name of theBuddy = myAnnoyingBuddyName) then
      send replyMsgAnnoy to theBuddy
    end if
  end message received

JMichaelTX thank you so very much. I am impressed. I will give it a try and let you know how it works.