I’ve got a small script called from a Mail Rule every time a new message arrives, that announces the arrival, and calls the main email processing application.
When several sequential messages arrive, the script runs multiple times, resulting in ‘echoes’.
I’ve add a condition using a time storing property that only allows the script to run every 10 seconds, and it works fine when run as a script or application, but the Mail Rule somehow treats it differently, and the echoes are persisting.
Anyone know of a way or getting the Mail Rule to treat the script normally, thus restricting the speech to every 10 seconds, please?
(*
set p to ((path to desktop) & "Mail Manager Caller.app" as text)
repeat 10 times
tell application p to run
end repeat
*)
property mailManagerDesktopFolderPath : ""
property ch : (current date) - 6
property speechTest : true
on run
my runtest()
end run
on runtest()
if (current date) > my ch then
set my speechTest to true
set my ch to (current date) + 10
else
set my speechTest to false
end if
set pathToMMDefaults to (path to preferences folder from user domain) & "MeSelf-Software.Mail-Manager.plist" as text
tell application "Finder" to set fileFound to exists file pathToMMDefaults
if fileFound then
set my mailManagerDesktopFolderPath to my getpath(pathToMMDefaults)
if my speechTest then
if my mailManagerDesktopFolderPath ≠ "Error" then
tell application "Finder" to set MMFound to exists folder (my mailManagerDesktopFolderPath)
if not MMFound then
set my mailManagerDesktopFolderPath to (path to desktop) & "Mail Manager Folder" as text
tell application "Finder" to set MMFound to exists folder (my mailManagerDesktopFolderPath)
end if
if not MMFound then
say "The Mail Manager Folder has been re-located, or is missing."
end if
else
say "The Mail Manager defaults p list file in the preferences folder, in user library folder, has been re-located, or is missing."
end if
end if
end if
try
set temp2 to my ReadFile2(" SwitchMailManagerFlag.dat")
if temp2 is not in {"COMPLETELY OFF"} then
try
tell application "Finder"
if my speechTest then
if temp2 is in {"STANDINGBY", "STANDBYRESTART"} then
say "Mail has arrived. Mail Manager is in standby." using "Vicki"
end if
if temp2 = "STANDBYWAIT" then
say "Mail has arrived. Mail Manager is waiting to go into standby." using "Vicki"
end if
end if
if not (exists process "Mail Manager") then
ignoring application responses
tell application ((path to applications folder) & "Mail Manager:Mail Manager" as text) to activate
end ignoring
end if
end tell
end try
else
set tempFlags to my retrieveSpeakErrorsFlag()
if item 1 of tempFlags = true then
if item 2 of tempFlags = true then
if temp2 = "COMPLETELY OFF" and my speechTest then
say "Mail has arrived. Mail Manager is off." using "Vicki"
end if
end if
end if
end if
on error errMsg number errnum
if errnum ≠ -128 then tell me to display dialog errMsg & return & return & errnum
end try
end runtest
on getpath(pathToMMDefaults)
set plistFile to POSIX path of pathToMMDefaults
set theKeys to {"mailManagerDesktopFolderPathArchive"} -- the keys to get values of
set X to 1 -- begin with the first array item
set theResult to {} -- this will be the values of the keys of the array items
tell application "System Events"
try
set thePlistKey to property list file plistFile
set thePlistElement to (get property list item "mailManagerDesktopFolderPathArchive" of thePlistKey)
return value of thePlistElement
on error errMsg number errnum
return ((path to desktop) & "Mail Manager Folder" as text)
end try
end tell
end getpath
on retrieveSpeakErrorsFlag()
set thePPath to POSIX path of (my mailManagerDesktopFolderPath & " General Data.plist" as text)
set theFlag to true
tell application "Finder"
if not (exists file (my mailManagerDesktopFolderPath & " General Data.plist" as text)) then set theFlag to false
end tell
if theFlag then
tell application "System Events"
try
set thePlistKey to property list file thePPath
set thePlistElement to (get property list item "sayEveryErrorMessageKey" of thePlistKey)
set sayEveryErrorMessage to value of thePlistElement
on error errMsg number errnum
set theFlag to false
end try
end tell
end if
return {theFlag, sayEveryErrorMessage}
end retrieveSpeakErrorsFlag
on ReadFile2(TheFileName)
set TheFileName to my mailManagerDesktopFolderPath & TheFileName as text
tell application "Finder"
try
set WholeList to read file (TheFileName)
return WholeList
on error
return {}
end try
end tell
end ReadFile2
on quit
continue quit
end quit