text from Mail rule

I’ve created a simple script to have Messages text me when an email with a specific subject is received in my Inbox:

tell application "Messages"
	send "You have a package waiting for you at the UPS Store" to buddy "[my cell number]" of service "E:[my email address]"
end tell

(I used my cell number because if I put my name Messages said it didn’t have my name in the buddy list).

The script runs, except that I have received multiple instances of the test message in the past couple of hours; I’m assuming this is because I’m sending it to myself and it’s causing a loop inside the Messages environment.

I’m often out of my office, and getting a text instead on an email would be useful.

I’d appreciate any thoughts on how to get round this, as well as how to stop the initial test message from continuing to be delivered.



Hi. It may be helpful to post the rule portion of the script, since it’s the trigger. I don’t have ML and am curious; what is the advantage”if any”to sending the text from Messages, rather than Mail?

You can send to a phone number, and it arrives like a text/SMS message.

Hi, Shane. That can be done from Mail, as well, even with smaller and prepaid carriers. I don’t text anyone outside North America, so perhaps that’s only a US thing?

It may be a US thing, but there’s also the matter of convenience/UI. Look here and it might become clearer:

I guess a prime advantage is that not sending as an SMS message invokes no carrier charges.

The rule says:



That will run in an infinite loop. You deleted the original incoming Mail message, but you sent out a new one that will trigger the rule.

I’m not sure I understand what you mean - the message comes in, meets the rule’s criteria; that triggers the AppleScript and deletes the incoming message.

Where does a new email get triggered?



I may misunderstand how Messages works. I’m used to using Mail to send out SMS texts, and the replies come back in the form of regular email. If the Messages app”not Mail”is the receiver of the new message, then the Mail rule wouldn’t be triggered, as I initially thought. I just saw the below article from Cult of Mac, which may be apropos. Perhaps the multiple texts you received are actually just alerts?

Thanks for the link. It’s possible the alerts were what I was seeing, though it was over a period of several hours. I’ve set repeat to Never on both iOS devices. If I get a chance, I’ll test it later.

Thanks for your help.