G’day all
After initial success with Marcs efforts, I continued to test my version of his script, and found that its reliability gradually diminished, until it no longer works at all when setting both the ‘enabled:true’ and the name of the script that I want to use. I always see ‘No script selected’ in the rule. I’ve also re-booted twice.
As I require the Mail rule to ALWAYS be set, I’m going to have to fall back on the GUI, which seems reliable, but slow and cumbersome in comparison to direct scripting.
Marc, either something is wrong with my Yosemite install or hardware, or Mail rule scripting is unreliable. I have never, with your script, had success at setting ‘enabled:true’, so I’m wondering if it works consistently with your setup, or if there’s a bug in my Mail app.
I tried setting the script file to both a file (path) and an alias, but the script still won’t select the file.
My latest effort is below.
Regards, and Merry Christmas to all,
Brian Christmas (aka Santa)
my mailRuleCreator:("StartUpTest")
on mailRuleCreator:sender
set isThisStartUp to (sender as text is "StartUp")
set acctConstant to «constant eruttacc»
set libFolder to (path to library folder from user domain)'s POSIX path
set pathToApplicationScripts to (path to library folder from user domain) & "Application Scripts:" as text
tell current application to delay 0.2
set existMMCallerScript to false
try
tell application "Finder" to set theCallerFile to (pathToApplicationScripts & "com.apple.mail:Mail Manager Caller.scpt" as alias)
set existMMCallerScript to true
end try
if existMMCallerScript then
tell application "Mail"
activate
if not (exists mailbox "* items to shift") then make new mailbox with properties {name:"* items to shift"}
--delete rules
try
delete (every rule where name contains "Automation")
end try
set acctName to false
if not (exists rule "Move to '* items to shift'") or not isThisStartUp then
set acctName to choose from list (get accounts's name whose enabled is true) with prompt "Please choose an Account to which to add the Mail rule " & return & return & "\"Move to '* items to shift'\"." & return with title "Mail Manager add Mail rule" OK button name "Choose this Inbox Account" cancel button name "I'll set the rule myself"
end if
if acctName ≠false then
try
if not isThisStartUp then delete (every rule where name contains "items to shift")
end try
tell current application to delay 0.2
set acctName to acctName's item 1
set directory to ((account acctName's account directory) as rich text)'s POSIX path
--ACTIONS
if not (exists rule "Move to '* items to shift'") then
make rule at beginning with properties {name:"Move to '* items to shift'", should move message:true, all conditions must be met:true, stop evaluating rules:false, enabled:true, run script:theCallerFile, move message:mailbox "* items to shift"} #
--CONDITIONS
make rule condition at rule 1 with properties {rule type:acctConstant, expression:(my augment(libFolder, directory))}
end if
end if
set the enabled of rule "Move to '* items to shift'" to true
end tell
else
tell application "System Events" to display dialog "There does not appear to exist a Mail Script called 'Mail Manager Caller.scpt'." & return & return & "Mail Manager cannot continue." buttons "OK"
end if
end mailRuleCreator:
on augment(libFolder, directory)
set text item delimiters to libFolder
("~/Library/" & directory's text item 2)'s text 1 thru -2
end augment
Model: Late 2014 retina i7, Yosemite
AppleScript: 2.4
Browser: Safari 600.2.5
Operating System: Other