I’ve got a mail rule that calls a numbers spreadsheet and updates it with info from the incoming message. Works just fine. Except…I also want the message to be marked as unread after the spreadsheet has been successfully updated.
1. In the rule, add the condition ‘mark as read’.
Problem: even though I add this condition after the ‘Run AppleScript’ action, it always moves to before it. The result of this is the message gets marked as unread, but my script doesn’t get called any my numbers sheet doesn’t update.
2. In the applescript, add the line
just before the end of the "perform action…" handler.
Problem: now the numbers sheet updates, but the message remains as unread.
Any ideas how do I get *both* of these to work together? Where can I put the ‘set read status..' line to make it work?
The whole mail handler looks like this (with some creative substitutions for public posting):
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
--get customer name from msg content
set this_item to item 1 of theMessages
set theTxt to this_item's content
set ttl to offset of "Price" in theTxt
set pricePaid to rich text ttl thru -1 of theTxt
set theTotal to paragraph 1 of pricePaid
set theNum to rich text 9 thru -1 of theTotal
set theInt to theNum as number
if theInt is greater than 0 then
set fellaMeLad to offset of "Customer" in theTxt
set lessTxt to rich text fellaMeLad thru -1 of theTxt
set ourHouse to offset of "Address" in lessTxt
set stripIt to rich text 1 thru ourHouse of lessTxt
--get the email address from msg content
set theParagraphs to paragraphs of stripIt
set theCustard to paragraph 3 of stripIt
set theEmail to paragraph 4 of stripIt
if theEmail does not contain "@" then
set theEmail to paragraph 5 of stripIt
end if
-- get the product from the subject line
set theSubjectLine to this_item's subject
set theProdNum to offset of theCustard in theSubjectLine
set lessSubjectLine to rich text theProdNum thru -1 of theSubjectLine
set removeCustard to offset of "- " in lessSubjectLine
set theSubjectLine to rich text (removeCustard + 2) thru -1 of lessSubjectLine
set gotProduct to 0
-- oh if only we had switch and case...
set theSource to ""
if theSubjectLine contains “blah blah" then
set theSource to “blah"
set gotProduct to 1
end if
if theSubjectLine contains “blob blob" then
set theSource to “blob"
set gotProduct to 1
end if
if theSubjectLine contains “bling bling" then
set theSource to “bling"
set gotProduct to 1
end if
if theSubjectLine contains “blam blam" then
set theSource to “blam"
set gotProduct to 1
end if
if gotProduct = 0 then
set theSource to "Unknown Product"
end if
my letsDoNumbers(theSource, theCustard, theEmail)
— everything works OK up to this point, however...
—this doesn’t work:
set read status of theMessages to true
end if
end tell
—putting it here instead doesn’t work either:
#set read status of theMessages to true
end perform mail action with messages
end using terms from