Mail Rule

Hello, Im using this mail rule, or I was under Tiger, now I can’t get it to work on Leopard, only if I use the rule man, i’ve added it as a rule for all incomming messages, but nothing works, can somebody tell me why


(*
	Save mail as PDF.
*)
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
					set theId to id as Unicode text
				end tell
				set theAccount to name of account of mailbox of eachMessage
			end tell
			set thedate to short date string of thedate
			set oldDelims to AppleScript's text item delimiters
			set AppleScript's text item delimiters to {"."}
			set thedate to text items of thedate
			set AppleScript's text item delimiters to oldDelims
			set thedate to text items of thedate as text
			set mailPath to make_folder(path to documents folder, "Mails")
			set AccountFolder to make_folder(mailPath, theAccount)
			set IDFolder to make_folder(AccountFolder, theId)
			set TempFile to (IDFolder as Unicode text) & theSender & "_" & theSubject & ".txt"
			try
				set theTextFile to open for access TempFile with write permission
				write "From: " & theSender & return & "Date: " & thedate & return & "Subject: " & theSubject & return & return & theContents to theTextFile
				close access theTextFile
			end try
			set the_posix_file to POSIX path of TempFile
			set terminalCommand to ""
			set convertCommand to "/System/Library/Printers/Libraries/./convert "
			set newFileName to the_posix_file & ".pdf"
			set terminalCommand to convertCommand & "-f " & "\"" & the_posix_file & "\"" & " -o " & "\"" & newFileName & "\"" & " -j \"application/pdf\""
			do shell script terminalCommand
			tell application "Mail"
				repeat with theAttachment in (get eachMessage's mail attachments)
					set theFileName to (IDFolder as Unicode text) & "#" & theId & space & theAttachment's name
					try
						save theAttachment in theFileName
					on error errNum
					end try
				end repeat
			end tell
		end repeat
	end perform mail action with messages
end using terms from
on make_folder(fPath, fName)
	try
		return ((fPath as string) & fName) as alias
	on error
		tell application "Finder" to set newfolder to make new folder at fPath with properties {name:fName}
	end try
	return newfolder as alias
end make_folder

/mkh

bump :confused: can somebody plz help me with this, need it so bad to be working again :&

What doesn’t work? Describe where and how it fails.

Hello Adam, well, I have added the script as a rule for all incomming mails, the script IS working but only if i run it man, in Tiger it would run every time I got an email, but with Leopard it don’t seem to behave the same way, and I have no idea why this should be a problem, I guess Mail 3.0 handles rules in a different way…

/mkh

In the Rules pane of Mail Preferences have you selected “Every Message” or whatever conditions apply, chosen “Run AppleScript”, and then with the “Choose” button, navigated to the script saved as a compiled script (.scpt extension)?

Hey, yes , I did just as you described…

Is that rule first in the stack? Rules can be dragged around and are applied in the order in which they appear. If others trigger first, this one may be missed.

AHA, that might be the problem, thanks alot