Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 20, 2013, 04:43 PM   #1
juju01
macrumors newbie
 
Join Date: Mar 2008
applescript to send new email

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 by juju01; Jan 20, 2013 at 05:39 PM.
juju01 is offline   0 Reply With Quote
Old Jan 21, 2013, 06:45 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Jan 22, 2013, 07:02 AM   #3
juju01
Thread Starter
macrumors newbie
 
Join Date: Mar 2008
Quote:
Originally Posted by kryten2 View Post
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.
juju01 is offline   0 Reply With Quote
Old Jan 22, 2013, 04:24 PM   #4
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:02 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC