AppleScript Auto-Reply to Messages from specific contact

Hi All,


So I'm not super technical, however through a few hours of research I think that AppleScript is what I'm looking for this site seemed the best place.


I'm looking for someone who will help me (I'm totally willing to send some money via PayPal, etc) - who can try and give me a working solution I can just run that will run on either my Mac (currently on High Sierra 10.13.1) or iPhone (I know much less likely) that allows the capability to auto-reply to an iMessage / Message from ONLY ONE contact that I specify (not auto-reply to all) with one of a few pre defined responses.


Anyone that could help with this please let me know! Thanks so much.

MacBook Air, macOS High Sierra (10.13.1)

Posted on Mar 8, 2018 3:51 PM

Reply
4 replies

Mar 9, 2018 12:44 PM in response to aes295

Oh man, you're absolutely right - you said message, and I read 'email message'. My bad.


Messages is actually much easier. Try:


property myReplies : {"Hi", "thanks for calling", "Have a nice day :)", "I'll get back to you"}


using terms from application "Messages"


on message receivedtheMessagefromtheBuddyfortheChat



-- chage this line to match the name of the person you want to trigger on

if name of theBuddy = "Joe Smith" then

set msgReply to some item of myReplies


sendmsgReplytotheBuddy

end if

end message received



# The following are unused but need to be defined to avoid an error



on received text invitationtheTextfromtheBuddyfortheChat

end received text invitation


on received audio invitationtheTextfromtheBuddyfortheChat

end received audio invitation


on received video invitationtheTextfromtheBuddyfortheChat

end received video invitation


on received file transfer invitationtheFileTransfer

end received file transfer invitation


on buddy authorization requestedtheRequest

end buddy authorization requested


on message senttheMessagefortheChat

end message sent


on chat room message receivedtheMessagefromtheBuddyfortheChat

end chat room message received


on active chat message receivedtheMessage

end active chat message received


on addressed chat room message receivedtheMessagefromtheBuddyfortheChat

end addressed chat room message received


on addressed message receivedtheMessagefromtheBuddyfortheChat

end addressed message received


on av chat started

end av chat started


on av chat ended

end av chat ended


on login finishedfortheService

end login finished


on logout finishedfortheService

end logout finished


on buddy became availabletheBuddy

end buddy became available


on buddy became unavailabletheBuddy

end buddy became unavailable


on completed file transfer

end completed file transfer

end using terms from

Save it as a compiled script in ~/Library/Application Scripts/com.apple.iChat, then it should be available under the 'AppleScript handler' option in Messages preferences.

Mar 8, 2018 9:21 PM in response to aes295

This is pretty trivial, all things considered but, as with most things the devil is in the details 🙂


The hardest part doesn't even involve AppleScript at all - triggering based on the specific sender address. Just create a Mail Rule (Mail -> Preferences -> Rules) that triggers when the sender matches the email address in question:


User uploaded file

User uploaded file


(you do this after you create the AppleScript in question and save it in ~/Library/Application Scripts/com.apple.mail)


The script itself would look something like this:


-- This is a list of the response texts.

-- Extend this list as much as you like

set autoreplies to {"Thanks for emailing me", "Have a great day!", "Remember to smile"}


using terms from application "Mail"

on perform mail action with messagestheMessagesfor ruletheRule

tell application "Mail"


-- loop through the incoming messages

repeat with eachMessage in theMessages


-- get the sender's address


-- The Mail.app rule that invokes this script ensures that it's from who we expect


-- but we can add additional logic here if needed

set theName to extract name fromsender of eachMessage

if exists reply to of eachMessage then

set theAddress to reply to of eachMessage

else

set theAddress to extract address fromsender of eachMessage

end if



-- select a random response from above

set messageText to some item of autoreplies


-- create a new outgoing message

set newMessage to makenewoutgoing messagewith properties {content:messageText}


-- set the message parameters

tell newMessage


makenewto recipientat end of to recipientswith properties {name:theName, address:theAddress}

set visible to false

set subject to "Re: " & subject of eachMessage

end tell


-- and send it


sendnewMessage

tell eachMessage

set was replied to to true

end tell

end repeat

end tell

end perform mail action with messages

end using terms from


Use Script Editor to save this script in ~/Library/Application Scripts/com.apple.mail and you should be all set.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript Auto-Reply to Messages from specific contact

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.