I have a mail rule which works on the whole just fine, but there’s a couple of niggles.
The first one is a curiosity, but one I’d like to understand.
For some reason, whenever I edit, recompile and save the rule, the first run results in nothing happening. The second and subsequent runs work as expected (save for niggle 2, below).
Nothing changes between the first run and the second. The script isn’t edited or even open. It’s as if the AppleScript component needs to “see it” once before acting on it. The problem does not recur after a login or restart. It only recurs if I edit the script again.
Anybody have any idea why that might happen?
The second niggle, which I think is down to some error in my scripting, is that the rule often fires on a previous message rather than the latest one in the door. Should I be explicitly deslect the message after I’m done with it?
Here’s a pared down copy of the script. I don’t think the Numbers handler is relevant, but I’ve included it just in case.
TIA
Phil
set targetWord to "whatever" tell application "System Events" set theUserPath to (home folder's path as text) end tell set the theSpreadsheet to "Documents:myNumbers.numbers" set theSpreadsheet to theUserPath & theSpreadsheet
using terms from application "Mail" on perform mail action with messages theMessages for rule theRule repeat with i from (count of theMessages) to 1 by -1 set this_item to item i of theMessages tell application "Mail" set mb to name of mailbox of this_item if mb = "INBOX" then set theTxt to this_item's content if theTxt contains targetWord then -- do some stuff here -- -- my letsDoNumbers(a, b, c, d, e) end if end if set read status of this_item to true -- deselect the message here?
end tell end repeat end perform mail action with messages end using terms from
on letsDoNumbers(p, q, r, s, t) tell application "Numbers" activate open alias (my theSpreadsheet) tell document "AppRevenue.numbers" set this_sheet to (first sheet whose name is "A Sheet") tell this_sheet set _aTable to (first table whose name is "Table")
tell _aTable set theRng to cell theCol of row theRow add row above theRng set theDataToBeAdded to {p, q, r, s, t} set theIterator to 1
repeat with i from 1 to 5 set this_item to item i of theDataToBeAdded set theRng's value to this_item set theCol to theCol + theIterator set theRng to cell theCol of row theRow end repeat end tell end tell end tell end tell end letsDoNumbers
|