on removeImports()
tell application "Mail"
activate
try
if not (message viewer 1 exists) then make new message viewer
set mailbox list visible to true
end try
tell application "System Events" to tell process "Mail"
set temp to every row of outline 1 of scroll area 1 of splitter group 1 of window 1 as list
repeat with eachLine in reverse of temp
try
set tempValue to value of text field 1 of UI element 1 of eachLine as text
if word 1 of tempValue is "Year" then
set checkArrow to value of UI element 3 of UI element 1 of eachLine
if checkArrow = 1 then
activate
click UI element 3 of UI element 1 of eachLine
end if
end if
end try
end repeat
repeat
set getOut to true
set temp to every row of outline 1 of scroll area 1 of splitter group 1 of window 1 as list
repeat with eachLine in reverse of temp
try
set tempValue to value of text field 1 of UI element 1 of eachLine as text
if word 1 of tempValue is "Import" then
set getOut to false
set my processingList to tempValue
activate
select eachLine
click menu item "Delete Mailbox…" of menu 1 of menu bar item "Mailbox" of menu bar 1
click button 1 of sheet 1 of window 1
end if
end try
end repeat
if getOut then exit repeat
end repeat
end tell
end tell
end removeImports
Begin forwarded message:
Subject: I want to delete 'Mail' mailboxes.
Date: 9 May 2017 at 9:48:49 pm AEST
G’day scripters
Some days ago I posted about Importing mailboxes, which Yvan was kind enough to respond to, and I discovered that the ‘import’ command only worked on 1 layer deep mailboxes.
I now want some way of automatically removing what can be a lengthy list of imports mailboxes, but while delete message works, delete mailbox fails, even when I delete all the contained messages.
The mailboxes concerned are on the ‘On My Mac’ account, which reads as ‘missing value’ when trying to get the account.
I’ve tried just deleteing multi-level mailboxes, mailboxes with and without messages, etc, but the ‘delete’ command just doesn’t seem to work. I’ve also tried moving to the ‘trash mailbox’, which fails.
Any guidance please?
Regards
Santa
tell application "Mail"
set boxList1 to every mailbox whose name starts with (("Import") as list)
say (count of boxList1)
set theDeleteError to false
set x to 0
repeat with eachMailBox in boxList1
set internalList to mailboxes of eachMailBox as list
repeat with internalMailBoxes in internalList
set internalList to messages of internalMailBoxes as list
say (count of internalList)
repeat with eachmessage in internalList
try
delete eachmessage
end try
end repeat
set internalList to messages of internalMailBoxes as list
say (count of internalList) — zero
#tell application "System Events" to display dialog (name of internalMailBoxes) as text
do shell script ("sleep 1")
#delete mailbox ((name of internalMailBoxes) as rich text) of mailbox ((name of eachMailBox) as rich text)
delete internalMailBoxes —< fails
end repeat
delete eachMailBox
end repeat
end tell