Matt Gemmell

My new book CHANGER is out now!

An action-thriller novel — book 1 in the KESTREL series.

★★★★★ — Amazon

Mailbox Plister for Mailsmith

development 1 min read

I wrote an AppleScript yesterday which generates a hierarchical
Property List (.plist) containing information about all your mailboxes
in Mailsmith. The script can be 
<a href="http://www.scotlandsoftware.com/ftp/applescript/mailbox_plister.tgz">downloaded here</a>.



This might be of interest to Cocoa/Carbon developers who want to create 
applications which integrate with Mailsmith via AppleEvents/AppleScript, 
or indeed anyone who wants to know how to get hierarchical data from an 
application via AppleScript, and into your own applications.
&nbsp;



The generated property list is an array of dictionaries, with each 
dictionary representing a mailbox. Dictionaries have keys and values 
as follows:
Property Name Type Description
name string display name of the mailbox
id integer unique id of the mailbox
children array array of child mailboxes
The output is formatted to be as human-readable as possible, with proper
indenting etc (and nicer than that generated by Property List Editor, at
least for ASCII property lists). Take a look at some sample output in 
<a href="http://www.scotlandsoftware.com/blog/dev/applescript/plister_output_ascii.txt">ASCII plist format</a>, 
and in <a href="http://www.scotlandsoftware.com/blog/dev/applescript/plister_output_xml.txt">XML plist format</a>.



&nbsp;



The script allows setting the following options:
  1. Whether to generate a traditional (ASCII) property list, or a new-style XML one. XML is the default, using the Property List 1.0 DTD.
     
  2. Whether to generate empty "children" elements for mailboxes without children. If disabled, "children" elements will only be generated for mailboxes which have at least one child.
     
  3. You can also specify arbitrary text to prepend to all lines of the output. Could be useful for increasing the base indenting level, or for some other, more exotic purpose I can't think of at the moment!
&nbsp;



The resulting property lists can be used in pretty much any way you
want. You can save them to files and open and edit them with Property
List Editor, read them directly into Cocoa objects via the appropriate
convenience initialisers from NSArray or NSDictionary, or run the script
directly via an NSAppleScript instance and use NSString's -propertyList
method on the result to get your mailbox tree into memory. Could be
useful for <a href="http://www.scotlandsoftware.com/images/msmith_mailboxes_outline_view.png">populating an NSOutlineView</a>, 
for example. It's really up to you.



 Well, enjoy!