Getting Ready to Write an Apple Plug-in for Mac OS X

Blowing some dust off the old compiler this weekend… after about 8 years, I’m actually getting ready to write some real client-side software again.  Just a personal project, for fun.

Nothing fancy, but I’ve decided to see if I can’t write some useful plug-ins for Mac OS X.  In particular, I’m going to see if I can’t improve:

  • Apple Address Book
  • Apple Mail

I tend to joke with friends that when I went to business school, part of the admissions process was officially “turning in” my compiler.  To show you how dated I am, the last serious Mac OS development I did was in Metrowerks Codewarrior.

Over my vacation in August, I went through Cocoa in a Nutshell from the O’Reilly series, just to refresh my memory.  Even when I was on the WebObjects team at Apple, I primarily wrote framework code in Java, not Objective-C, so basically I’ve got to come up to speed again on:

  • Objective-C
  • XCode 2.4
  • Five versions of Mac OS X (the version I worked on became 10.0)
  • Documented methods of extending Apple Address Book
  • Undocumented methods of extending Apple Mail

I managed this weekend to get a sample plug-in for Apple Address Book working.  This wasn’t a huge feat, really, since XCode includes a sample project for this as a default install, and it’s fairly trivial to customize the three Objective-C messages that define the functionality.

If you are looking for the documentation on extending Apple’s Mac OS X Address Book, check out:

Pretty basic really, although adding a contextual menu command for certain fields is hardly the best interface.  I’ve been playing with Plaxo Toolbar for Mac, and trying to figure out how they inserted their drawer into the GUI.

Creating plug-ins for Apple Mail is much trickier, because it’s completely not supported or documented.  Well, I shouldn’t say not supported… it’s not supported officially.  However, Apple Mail does implement a plug-in architecture, and with a few quick setting changes, you can install a wide range of third party plug-ins.

Here are some cool links if you are interested:

  • Demystifying Mail App Plugins.  This blog post covers some high level tips and source code, in Python, to write a quick plugin.  Thanks to this post, I re-discovered class-dump, which lets you inspect the classes and methods for any Mac OS X application (very cool).
  • Mail Plugin Template 1.0. Aaron Harnly, you are my hero.  Aaron has posted an excellent XCode project template, with class-dump headers, for building your own Apple Mail plug-ins and installer scripts.  He even answered a simple project question for me over email.  Very cool.
  • CocoaDev.  This is a wiki site dedicated to Cocoa development.  Aaron’s code pointed me here, since it features “Method Swizzling”.  It’s a very sneaky feature of the Objective-C runtime, where you can effectively not only over-ride an method for an object you don’t own, but you can even replace the parent class method in applications that you don’t control!  Read this for specifics (very cool if you’re into programming).
  • Apple Mail Plug-Ins and Tools.  A whole directory site of Apple Mail plug-ins.
  • Apple Mail Plug-In Roundup.  This post on The Unofficial Apple Weblog covered a lot of cool plugins.
  • Mail Act-On.  Very cool plug-in that lets you map individual rules to keyboard commands.  My favorite Eudora feature, now on

So far, I have an Apple Mail plug-in that compiles and loads correctly in and logs data into the console.  But I’m going to put that in the “W” column for this weekend, given my incredible level of rust around the gears.

I’m going to be flying to Omaha this week to visit the LinkedIn customer service team… I’m going to try and use the flight time to get a little bit more working.

My biggest question now is how far can I go in terms of influencing the UI.  I already know how to:

  • Create a plug-in
  • Insert menu commands and menus into the main application
  • Create my own preferences panel & preferences file
  • Create my own window

However, if I really want to integrate,  I need to figure out how to:

  • Add commands to existing contextual menus (I can’t find them in the NIB files anywhere)
  • Add views/panes to the existing windows (ala a toolbar)

I haven’t found sample code that does either of the above yet, but I’m still looking.

All in all, it’s fun to be compiling again.

14 thoughts on “Getting Ready to Write an Apple Plug-in for Mac OS X

  1. If you come up with a way to export Apple Mail to a PST file, I’ll switch to a Mac in a heartbeat. There are plenty of apps out there that will let you do the opposite, but I don’t want to make the switch if there’s no way to back out of it if I don’t like it. That’s the main barrier to me making the switch.

  2. No way, man. PST is so scary even Microsoft hasn’t implemented two-way compatibility for the Mac. 🙂

    Besides, if you ever wanted to move back, I’m pretty sure Entourage can import from Apple Mail, and I’m pretty sure you can move from Entourage to Outlook.

    I’ve never heard of any problems moving to Outlook… only moving away from it.


  3. Dear Mr.Nash,

    I am in the process of implementing a CRM solution for one of our clients. we are evaluating both SugarCRM and VtigerCRM for them.

    The client uses Apple MACs on their desktop and servers. One of the requirements of that the client has is to be able to sync the contents of the CRM to the mail, contact and calendar applications on the desktop. As we do not have any expertise in house on development for OS X, I am looking for somebody to take up this project.

    If you would be interested in taking up this assignment, please let me know an approximate budget and time frame. In case you are not interested, please see if you can help me with locating somebody who can do the job.



  4. Adam,

    I just switched to from Eudora (something like 50-70 years of using Eudora, I’m 39, you do the math.) I love’s integration with the OS and other things about it. I definitely miss a lot of Eudora’s behaviors and keyboard shortcuts which don’t seem to be available with existing plugins and preferences.

    Since you’ve recently gotten in the mood to write plugins 🙂 and since you are obviously aware of the ‘Eudora Experience’…perhaps you’d like to write a ‘Eudora plugin’ to provide some of the missing functionality, options? (You know you want to do this.)

    -Control clicking on a field in a message box groups all messages in that box with that field.

    -“not junk”ing an email sends it back to the inbox

    -Separate mailboxes window

    -A transfer menu

    -attachments (as opposed to mandatory inline attachments)

    oh I could go on. Come on, write this thing…you’d be the hero of the Eudora ex-pat community.

    Anxiously awaiting the plugin.

    Rick Lupert
    Los Angeles

  5. Wow. That’s a lot of pressure. 🙂

    I don’t think my first plug-in will do all that. But I understand the sentiment. I would have stayed on Eudora forever if it had just kept up with HTML rendering and search capability at all well.

    I haven’t had any time to complete my plug-in the last two months – it’s been very busy at work. But I should have more time over the New Year. We’ll see if I get any coding done.


  6. Pingback: Method Swizzling in Cocoa « Psychohistory

  7. Pingback: Mac OS X: Method Swizzling in Cocoa « Psychohistory

  8. Adam – Good to see that you’re writing a Mail plugin! I just released a Cocoa/Objective-C version of MsgFiler. The original version was an AppleScript Studio app, and the difference in speed between AppleScript and Objective-C is amazing. Let me know if you need any tips or sample code.

  9. Hi,

    Did get the to the contextual menu items added menu’s working? If so, please can you elaborate on this to us.

    Thank you very much

  10. Adam,

    since Entourage doesn’t have traditional plug-in architecture, and there is no official support or document. Even though can i get dump classes to create entourage plug-in.


  11. Adam,

    Thank you for the terrific reference sites. I called my local B&N and plan to pick up the Cocoa Programming book tomorrow to start digging into during our three hour drive south for Thanksgiving.

    I am more interested in the later areas of development you mentioned and manipulating the existing tool bar (Customize Toolbar) with a new icon, so I can perform specific behaviors to open emails without having to return to the main menu bar to do so. I would also like to change the apps behavior, so after deleting or moving an open email, the next email will automatically open, again, so not having to return to the primary view to double click and open the next email.

    I may be in touch, as I am a Mac newbie (web designer by trade), but have programming background that might be as old as you noted your last foray into the field was with the Macintosh.

    One quick question … it sounds like to create a Mail plugin I will definitely need to install the Xcode package, as what I will be needing for my code does not come installed natively on the Mac?

    I will check you out on LinkedIn to see if I can get your email address if you do not mind a few additional questions I suspect to have once I get started.

    Thank you in advance …

  12. Hi Adam, I am looking for a very small plugin that add a column in the mail list with the country of the origin of the client (client-ip field in the header of the mail). Would you know how difficult would this be ?

Comments are closed.