Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

juju01

macrumors member
Original poster
Mar 27, 2008
32
1
I am looking to generate a new email in response to email from twitter about a new follower. The twitter notification typically has the following format for the subject:

"Name (@twitter_username) is now following you on Twitter!"

I am looking for a mail script which does the following:

  1. extract the twitter username from the subject - the @username
  2. send an email with the username in the body. I am using a specific text for the subject of the new email.

I have a script which does all the above except extracting the username from the subject line. Here is the script on Pastebin

Will appreciate any help to tweak it to add the username extracting feature!

Thanks
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
One way of doing it would be something like this :

Code:
tell application "Mail"
	set theMessages to every message of mailbox "INBOX" of account "GMX" whose subject contains "Twitter"
	repeat with eachMessage in theMessages
		set theSubject to subject of eachMessage
		set thefirstoffset to offset of "(" in theSubject
		set thesecondoffset to offset of ")" in theSubject
		set twitter_username to characters (thefirstoffset + 1) thru (thesecondoffset - 1) of theSubject as string
		set theNewMessage to make new outgoing message with properties {subject:"Notify", content:"Welcome new twitter follower" & space & twitter_username, visible:true}
		tell theNewMessage
			activate
			make new to recipient at end of to recipients with properties {address:"email@someone.com"}
			--send
		end tell
	end repeat
end tell
 

juju01

macrumors member
Original poster
Mar 27, 2008
32
1
One way of doing it would be something like this :

Code:
tell application "Mail"
	set theMessages to every message of mailbox "INBOX" of account "GMX" whose subject contains "Twitter"


Thank you! This looks great. The first line is a throwing me off a bit. I am using a mail rule to trigger the script to run - only when a new message arrives. So with this code, do I use this in a mail rule ? Does the code above fire only when new messages arrive for the specified mail account? - which is what I want to do. Thanks again.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Unfortunately I hardly use Mail nor do I use Twitter so I had to send myself a few mails with the subject line you mentioned to test on. The first line was used to get me a list of message ids from a specific mailbox and account to work with and isn't needed when using a rule.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.