Some weeks ago a gentleman asked for help with email in the Mail app Mail Boxes not clearing properly.
I replied (and have lost his address), but forgot to add that my code adds a ‘delete’ command, which in turn was curtesy of another lister.
So, here’s the full code as I’ve used it in my app.
tell application "Finder"
if not (exists process "Mail") then tell application "Mail" to launch
end tell
tell application "Mail"
set my currentMailItem to {}
#
set my mailBoxProcessName to "* items to store"
try
if not (exists mailbox "* items to store") then make new mailbox with properties {name:"* items to store"}
end try
set tempMail to every message of mailbox "* items to shift"
if (count of tempMail) > 0 then
set theTempIDList to {}
repeat with eachmessage in reverse of tempMail
set end of theTempIDList to message id of eachmessage
set the mailbox of eachmessage to mailbox "* items to store"
end repeat
repeat with theTempID in theTempIDList
repeat with y from 1 to 11
try
if ((exists (some message whose message id is theTempID)) of mailbox "* items to shift") then
delete ((some message whose message id is theTempID) of mailbox "* items to shift")
else
exit repeat
end if
on error
exit repeat
end try
if y = 11 then
tell application "Finder"
tell application "Mail" to quit saving no
set x to 0
repeat
if not (exists process "Mail") then exit repeat
set x to x + 1
tell current application to delay 0.1
if x ≥ 40 then exit repeat
end repeat
if x ≥ 40 then
set The_app to "Mail"
try
tell application "System Events" to set pid to the unix id of process The_app as Unicode text
do shell script "kill " & pid
end try
end if
tell current application to delay 0.2
tell application "Mail" to launch
end tell
end if
end repeat
end repeat
end if