I made a few AppleScripts already to get the list of mailboxes out of Outlook. I know that many users have a lot of mailboxes. Like hundreds or mailboxes. Some mailboxes may have a low number of mailboxes and some may be even empty. We are going to modify the AppleScript we had to include only empty mailboxes.
I can count the number of emails in each mailbox by getting "count every message" from the mailbox. And then I only add the mailboxes to the list if NoOfEmails is equal to 0. You can easily modify the AppleScript to include mailboxes with mailboxes when you replace the "= 0" with "> 0".
Here is the relevant section of the AppleScript:
set NoOfEmails to count every message of currentFolder
if NoOfEmails = 0 then
set FolderName to name of currentFolder
--get full path of mailbox
set end of AllFolders to my replace_chars(PathSoFar & ":" & (FolderName), "::", ":")
end if
end if
The full AppleScript is below:
set AllFolders to {}
tell application id "com.microsoft.outlook"
set allMailFolders to get mail folders
repeat with currentFolder in allMailFolders
set NoOfEmails to count every message of currentFolder
if NoOfEmails = 0 then
set FolderName to name of currentFolder
set PathSoFar to ""
if FolderName is not missing value and (container of currentFolder is not missing value or account of currentFolder is not missing value) then
set ContainerName to "x"
set theContainer to currentFolder
repeat while ContainerName is not ""
set ContainerName to ""
try
set theContainer to container of theContainer
set ContainerName to name of theContainer
if ContainerName is missing value then
set theAccount to account of theContainer
if theAccount is not missing value then
set AccountName to name of theAccount
set PathSoFar to AccountName & ":" & PathSoFar
end if
else
set PathSoFar to ContainerName & ":" & PathSoFar
end if
end try
end repeat
set end of AllFolders to my replace_chars(PathSoFar & ":" & (FolderName), "::", ":")
end if
end if
end repeat
return AllFolders
end tell
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
Below is the result in Script Editor:
The first mailbox from the script is "Auf meinem Computer -> Posteingang" which is really empty:
And yes, verification is part of developing code. Ahem - I had used "> 0" instead of the "= 0" that I wanted. And therefore, my original result was incorrect.