Newbie: Mac Mail question

Hi Forum members,

I am trying to create an automator action where I can do the following:

  1. Have a dialog box ask for Name and Email address.
  2. Pass these 2 variables to New Mail Dialog and auto populate the Email address and the name should go into Dear field.
  3. I then click Send and off it goes.

Questions:

  1. I am able to use the TextEdit action to read only 1 variable but not both. Further I have no idea how to pass these variables to the Mail action???
  2. How do I populate the Email address and also substitute the next to Dear with the Name variable?

Is it possible to do all this with just Automator or will I have to learn Action Scrpting?

Any help is greatly appreciated.

Regards
Max

Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

Hello maxshafiq,
You are experiencing one of my biggest frustrations with Automator - things SEEM like they should work…and then they completely fail leaving you wondering why :frowning:

The Mail action is meant to take input in the form of files/folders - which it then attaches to the new mail message. Or, if the input is text then it puts this into the body of the message - there is no way to pass it the name and address of the recipient.

You can read in more than one variable if you get creative. Have the user input a string of text separated by commas (or any character you choose) and then parse this into the separate values (see “on parseInput(input)” of script below)


The script below allows you to enter the recipient name and email address separated by a comma, and a new message is created. I am not sure what you mean by “ next to Dear” since my Mail has no “Dear” in it.

The Workflow looks like this:

  • Ask for Text
    –Please enter: name, email@address.com separated by a comma
    *Run AppleScript
    –paste into the action the script below

property theSender : "myEmail@address.com"
property theSubject : "test"
property theBody : "stuff"

on run {input, parameters}
	
	set theData to parseInput(input)
	set theName to item 1 of theData
	set theAddress to item 2 of theData
	tell me to makeNewMailMessage(theName, theAddress)
	
	return input
end run

on parseInput(input)
	set theResult to {}
	
	-- STORE THE CURRENT DELIMITER
	set oldDelimiters to AppleScript's text item delimiters
	-- CHANGE THE DELIMITER TO OUR CHARACTER OF CHOICE
	set AppleScript's text item delimiters to ","
	-- PARSE THE TEXT INTO AN APPLESCRIPT LIST
	set theResult to every text item of input
	-- RESTORE THE OLD DELIMITER
	set AppleScript's text item delimiters to oldDelimiters
	
	return theResult
end parseInput

on makeNewMailMessage(recipientName, recipientAddress)
	try
		tell application "Mail"
			-- Properties can be specified in a record when creating the message or
			-- afterwards by setting individual property values.
			set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody}
			tell newMessage
				-- Default is false. Determines whether the compose window will
				-- show on the screen or whether it will happen in the background.
				set visible to true
				set sender to theSender
				make new to recipient at end of to recipients with properties {name:recipientName, address:recipientAddress}
			end tell
			-- Bring the new compose window to the foreground, in all its glory
			activate
		end tell
	end try
end makeNewMailMessage

For further customization you can replace the script properties theSender, theSubject, theBody by more variables entered into the comma delineated string - you just need to adjust the “on run {input, parameters}” function of the AppleScript to watch for these new values.

Let me know if this does what you need.
jON bEEBE