I have several ChronoSync documents, which are supposed to run on a schedule. Sometimes they don’t, and I want to be able to send an email to trigger a script to run the appropriate sync. So subject “run cs 4d” will run the 4d sync, and “run cs all” will run all of them.
The script is below. The issue is that when an email is received which runs the rule, the single message passed to the script isn’t the one that triggered the rule. Am I doing something wrong?
using terms from application "Mail"
on perform mail action with messages msgs
repeat with msg in msgs
set syncName to msg's subject
my logit(syncName, false)
set syncName to syncName's last word
tell application "ChronoSync Scheduler"
set syncs to scheduled items
repeat with sync in syncs
set itsName to sync's description
ignoring case
if (itsName is equal to syncName) or (syncName is "all") then
Synchronize sync
tell application "Mail" to delete msg
end if
end ignoring
end repeat
end tell
end repeat
end perform mail action with messages
end using terms from
on logit(str, noNL)
if (noNL is true) then
else
set backC to ""
end if
do shell script "echo " & (quoted form of (str & backC)) & " >> ~/Downloads/csmail.txt"
end logit