I'm an ass. The script failed when I removed the writeto instructions because I failed to remove a parameter in the instruction calling the handler and in the handler's entry one. They were : my letsDoNumbers(a, b, c, d, e, path2log) on letsDoNumbers(p, q, r, s, t, path2log)
but they were supposed to be :
my letsDoNumbers(a, b, c, d, e) on letsDoNumbers(p, q, r, s, t)
I took the opportunity to make other changes. I no longer store the path to the spreadsheet in a property because I dislike to store variable values in properties : these ones are saved on disk and it's not a good thing - mainly if we sign the scripts.
I define the name of the spreadsheet in a property so that we no longer face the original oddity when the name was different in the code supposed to define the path and the one supposed to speak to the document in the handler. Writing this property on disk is not a problem because, as it's not modified during execution there is no attempt to write something when running.
# Edited on 2017/06/03
property spreadsheetName : "AppRevenue.numbers"
using terms from application "Mail" on perform mail action with messages theMessages for rule theRule
tell me to set theUserPath to "" & (path to home folder) set shortSpreadSheet to "Documents:" & my spreadsheetName set theSpreadSheet to theUserPath & shortSpreadSheet
if theUserPath ends with "koenig:" then set targetWord to "Foncez" else set targetWord to "whatever" end if
tell me to set path2log to "" & (path to desktop) & "log_gol.txt" repeat with i from (count 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 -- -- set a to random number set b to random number set c to random number set d to random number set e to random number tell me to say "ready to call the handler" my letsDoNumbers(a, b, c, d, e, theSpreadSheet) # pass the path to the handler 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, theSpreadSheet) tell me to say "I am in the handler" tell application "Numbers" activate open alias theSpreadSheet repeat until exists document (my spreadsheetName) delay 0.1 end repeat
tell document (my spreadsheetName) tell sheet "A Sheet" tell table "Table" set theRow to 5 tell row theRow set theCol to 4 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 # table end tell # sheet end tell # document end tell # application end letsDoNumbers
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) samedi 3 juin 2017 15:02:10
|