Mail Rule > Trigger Applescript > AS send variables to Applscript App?

Hi All,

I have a rather lengthy Applescript that I trigger with a Mail Rule. Instead of Mail being tied up processing all that time could I just get the information I need from the message then pass that to an Applescript application bundle? There are four things I need from the message

Which I do with this:

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		repeat with eachMessage in theMessages

tell application "Mail"
				tell eachMessage
					set theSender to (extract name from sender)
					set theDate to date received
					set theContents to content as text
					set theSubject to subject as text
				end tell
			end tell

After that I don’t really even need Mail as everything thing else in the script uses other apps. Also Mail has been crashing in some sections of the script where I call up a dialog to give the user info. Is there a way to pass variables to a Applescript application bundle?


how about writing the variables to a temporary text file, then use your larger script to read the values from the text file and then delete it

set pathtodesktop to path to the desktop as string

set theSender to "the sender"
set theDate to "date received"
set theContents to "content as text"
set theSubject to "subject as text"

set theText to theSender & return & theDate & return & theContents & return & theSubject

	set fileRef to (open for access (pathtodesktop & "emailTemp.txt") with write permission)
	write (theText) to fileRef
	close access fileRef
on error
		close access fileRef
	end try
end try


Thanks for the response. I am incorporating your approach as well as doing a shell to write a plist file. So when a client orders an image from our web site’s client area the email message from the form on the site is of a controlled format so what happens is

  1. Mail triggers a script.

  2. The script extracts info from the message and writes an order file to the folder of the job and writes the location of the order file to the .plist file for my Applescript app “Process Lightbox Order”.

  3. Launches the Applescript app which looks at the plist file to get the location of the order file it needs to process.

  4. Opens the order file extracts the list of images ordered, loads the job, tags & processes the images.

  5. Clears the plist file.

I’m basically using the plist file as a process queue so if more then one order is received at a time it will queue them. So at the end of each run it will advance any that are waiting to the next position and run again. I almost have it finished and will post it. It will achieve my main goal which was to free up Mail from waiting while the script ran. What really makes that work though is using

ignoring responses

end ignoring

So the script Mail triggers doesn’t wait for a response from the Applescript app.