Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 10-09-2009, 12:02 PM   #1
agent69akasexy
Prospect
 
Join Date: Oct 2009
Posts: 1
Question Sending an auto-reply from Mail with applescript

I am trying to send an email back to the person that sent one to me telling the itunes track & artist that is currently playing.

I've got it to send one to a certain email adress Which is

Code:
tell application "iTunes"
	set trk_arts to the artist of the current track
	set trk_name to the name of the current track
	set playlisto to the name of the current playlist
	
end tell


tell application "Mail"
	delay 3
	set theMessage to make new outgoing message with properties {visible:true, subject:"Answer:", content:"The Current Track is \"" & trk_name & "\" by " & trk_arts & ". iTunes is currently in the playlist \"" & playlisto & "\""}
	tell theMessage
		make new to recipient with properties {address:"MY ADDRESS"}
	end tell
	send theMessage
end tell
but i cant figure out how to send that to the email that sent a message to me. I've got this:

Code:
on perform_mail_action(info)
	tell application "iTunes"
		set trk_arts to the artist of the current track
		set trk_name to the name of the current track
		set playlisto to the name of the current playlist
		
	end tell
	tell application "Mail"
		
		set theMessages to |SelectedMessages| of info
		repeat with thisMessage in theMessages
			set AppleScript's text item delimiters to {""}
			set thisSender to sender of theMessages
			
			set theNewMessage to make new outgoing message with properties {visible:true, subject:"Answer:", content:"The Current Track is \"" & trk_name & "\" by " & trk_arts & ". iTunes is currently in the playlist \"" & playlisto & "\""}
			tell theNewMessage
				make new to recipient with properties {address:thisSender}
			end tell
			send theNewMessage
			
			
		end repeat
	end tell
end perform_mail_action
agent69akasexy is offline   Reply With Quote
Old 10-09-2009, 05:36 PM   #2
kainewynd2
Triple-A Player
 
Join Date: Nov 2005
Location: Eastern US
Posts: 124
Smile

This is essentially a "Me too" message, but I am looking to do something similar.

Are you currently able to send an email just fine if you hard code the send-to address, but can't find a way to grab the original sender's email? If so, that is where I am as well. If not, I can help you get to that point.

Just let me know.
kainewynd2 is offline   Reply With Quote
Old 10-11-2009, 06:36 PM   #3
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 3,342
if you're trying to get mail to do this automatically from a rule, you need to put it is as 'on perform mail actions' block, like so:
Code:
using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "iTunes"
			set trk_arts to the artist of the current track
			set trk_name to the name of the current track
			set playlisto to the name of the current playlist
			
		end tell
		tell application "Mail"
			repeat with thisMessage in theMessages
				set AppleScript's text item delimiters to {""}
				set thisSender to sender of theMessages
				
				set theNewMessage to reply thisMessage with opening window
				tell theNewMessage
					set content to "The Current Track is \"" & trk_name & "\" by " & trk_arts & ". iTunes is currently in the playlist \"" & playlisto & "\""
				end tell
				
				send theNewMessage
				
			end repeat
		end tell
	end perform mail action with messages
end using terms from
note that I've simplified things by using the 'reply' command rather than building a new email from scratch. however, if you want to do the old version where you build a new email, I think you need to say it like this (change in green):
Code:
tell theNewMessage
	make new to recipient at end of to recipients with properties {address:thisSender}
end tell
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Reply

Tags
applescript, auto-reply, itunes, mail, programming

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 11:36 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.