Mail triggered script not working

Can anyone tell me why this script, that’s triggered by a Mail rule, isn’t working?
The Mail rule sets a background colour, sets a flag, then runs the applescript below:

-- Web stuff reminder script --
--
-- This script creates reminders for web stuff.
-- It's triggered by an email (via Mail), and creates a reminder based on the V number of the item that's gone to print.
-- Note that the script uses a Mail rule to activate

-- Process is:
-- Get the V number from the subject email
-- Create a reminder in Reminders with the name of the email subject line

on perform_mail_action(info)
	tell application "Mail"
		if read status of theMessage is false then
			
			if frontmost then return -- don't announce if Mail is frontmost
			set selectedMessages to |SelectedMessages| of info
			repeat with theMessage in selectedMessages
				set theSubject to subject of theMessage
			end repeat
		end if
	end tell
	-- ALL DONE!
	-- Now create some reminders - one for each of the different vendors
	-- IMPORTANT! YOU MUST HAVE A REMINDER LIST TITLED "Web Stuff" OR THIS PART OF THE SCRIPT WILL FAIL
	
	tell application "Reminders"
		activate
		my create_reminder(theSubject)
		
	end tell
	
end perform_mail_action



-- START SUBROUTINES --
-- ******************************************************************
on create_reminder(reminderTitle)
	tell application "Reminders"
		tell list "Web Stuff"
			make new reminder with properties {name:reminderTitle}
		end tell
	end tell
end create_reminder
-- ******************************************************************


I’ve read a few posts that say script triggers are broken in Mail under Mountain Lion “ but also plenty that have said it works!

Hello!

Try inserting try error blocks, if you use the handler I have posted here, then you can open the accompanying log file in console app, (from the sidebar) and see what is going on.

try
# A tell block inside here.

on error e number n
	my logit("block 1: " & e & " : " & n, "mailrule")
end try


to logit(log_string, log_file)
	do shell script ¬
		"echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬
		"\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit

Hi. I don’t have ML, so I don’t know if the example is workable, but, on initial inspection, the subroutine call appears incorrectly placed outside the loop and the initial tell block to “Reminders” is unnecessary. As the loop now stands, theSubject could only be the final value.

repeat with theMessage in selectedMessages
				my create_reminder(theMessage's subject)
			end repeat

And that’ll remind me, to not just pass the logit handler when I hear mail rule, but go for greater granularity! :slight_smile:

I think a good approach here would be to first collect the subjects in the Mail.app block then iterate over it to call reminders. (I don’t have ML either).


set subjList to {}

# in your repeat over messages loop
set end of subjlist to theSubject

# then when you are to make reminders

repeat with aSubj in subjlist
  my create_reminder(aSubj)
end repeat