Sorry about the amount of traffic I’m generating, but Sierra has some real issues.
I’ve once again struck problems with the Mail.app. Apple seems to have once again stuffed things up.
It refuses to create nested folders, and I’ve tried lots of methods, including ending the creation string with “/“. No success.
I can’t find anything Googling, it’s simply too new.
set tempYearString to "Year 2017"
property theMonth : "09"
property dailyName : "02"
tell application "Mail"
activate
######################################################
# Make Yearly mailbox
######################################################
# This works
if not (exists mailbox tempYearString) then
say "year"
make new mailbox with properties {name:tempYearString}
repeat until exists mailbox tempYearString
do shell script ("sleep 0.1")
end repeat
end if
######################################################
# Make Monthly mailbox
######################################################
set loopCounter to 0
if not (exists mailbox (my theMonth) of mailbox tempYearString) then
#Fails
try
make new mailbox with properties {name:(tempYearString & "/" & (my theMonth))}
on error errmsg
tell application "System Events" to display dialog "1 " & errmsg
end try
# Fails
try
make new mailbox at mailbox tempYearString with properties {name:(tempYearString & "/" & (my theMonth) )}
on error errmsg
tell application "System Events" to display dialog "2 " & errmsg
end try
try
make new mailbox at mailbox tempYearString with properties {name:(my theMonth)}
on error errmsg
tell application "System Events" to display dialog "3 " & errmsg
end try
set x to 0
end if
set loopCounter to loopCounter + 1
do shell script ("sleep 0.1")
try
if not (exists mailbox (my theMonth) of mailbox tempYearString) then
activate
set selected mailboxes of message viewer 1 to mailbox tempYearString
tell application "System Events" to tell process "Mail"
click menu button 2 of splitter group 1 of window 1
click menu item "Erase Deleted Items…" of menu 1 of menu button 2 of splitter group 1 of window 1
set x to 0
repeat until exists sheet 1 of window 1
do shell script ("sleep 0.1")
set x to x + 1
if x ≥ 30 then exit repeat
end repeat
keystroke return
end tell
end if
end try
try
tell application "Mail"
if exists mailbox (my theMonth as rich text) of mailbox (tempYearString as rich text) then exit repeat
end tell
on error errmsg number errnum
if errnum ≠ -2763 then if my runForOz then tell application "System Events" to display dialog "MainProcessingLoops's transferMessageMailboxCreator exit loop " & errmsg & " number is " & errnum & return & my theMonth & return & tempYearString as text giving up after 40
exit repeat
end try
do shell script ("sleep 0.1")
######################################################
# Make Daily mailbox
######################################################
if not (exists mailbox (my dailyName) of mailbox (my theMonth) of mailbox tempYearString) then
# activate
try
make new mailbox with properties {name:(tempYearString & "/" & my theMonth & "/" & my dailyName)}
on error errmsg
tell application "System Events" to display dialog "4 " & errmsg
end try
end if
end tell