SHARE
TWEET

Mail: delete empty local mailboxes

applehelpwriter Apr 9th, 2014 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. script by Phil Stokes
  3. www.applehelpwriter.com
  4. 2014
  5. Purpose:
  6. Mail.app: Delete empty sub-mailboxes of a local ('On my mac') mailbox
  7.  
  8. The script below will delete the empty sub-mailboxes of the parent box whose name you supply in the dialog. i.e., if you supply the name 'Parent' then this
  9.  
  10. Parent
  11.      Child A (0)
  12.      Child B (0)
  13.      Child C (1)
  14.  
  15. will end up with
  16.  
  17. Parent
  18.      Child C (1)
  19.  
  20. However, tread lightly. It only goes one-level deep. It will ignore any subboxes of subboxes. Thus if you have
  21.  
  22. Parent
  23.      Child A (0)
  24.           SubChild (1)
  25.      Child B (0)
  26.  
  27. and you supply the 'Parent' to the script, you'll end up with
  28.  
  29. Parent
  30.  
  31. Note there are no confirmation 'warnings' boxes. It's pretty ruthless. You use this at your own risk.
  32. *)
  33.  
  34. --
  35. display dialog "Name of the parent mailbox:" default answer ""
  36. set mbx to text returned of the result
  37. tell application "Mail"
  38.           tell mailbox mbx
  39.                     set i to 1
  40.                     repeat while (count of its mailboxes) is not 0
  41.                               try
  42.                                         if (number of messages of its mailbox i) is 0 then
  43.                                                   set aName to name of its mailbox i
  44.                                                   tell application "Mail" to delete mailbox aName
  45.                                         else
  46.                                                   set i to i + 1
  47.                                         end if
  48.                               on error
  49.                                         exit repeat
  50.  
  51.                               end try
  52.                     end repeat
  53.           end tell
  54. end tell
  55. --EOF
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top