The Mysteries of iCal, Revealed!

Note: As of Snow Leopard, this functionality has been superseded by an official Dock tile plug-in mechanism.

One of the minor yet shiny new features of Mac OS X 10.5 is that iCal’s dock icon now shows the correct date even when iCal is not running. Some assumed this to be hard-coded functionality in the dock, but a few brave souls – well, one, being me – decided to find out.The following lines in iCal’s Info.plist are a bit of a hint:


iCalDockExtra.bundle can be found in iCal’s Resources directory. 90 seconds with class-dump, otool, and class-dump again show that the bundle implements a subclass of DockExtra, which in turn is defined in the private SystemUIPlugin.framework.

Having retrieved the interface declaration for the DockExtra class from class-dump, it is a simple matter to implement a subclass which logs which methods are called and when. As it turns out, the only ones called are -_initWithController: and -dealloc, but through the power of my mighty brain I worked out that I could draw the dock icon whenever I wished, using -getContext: to get a drawing context and size, -setDockImageFromContext to update the image in the dock and -releaseContext to clean up afterwards.

And that’s pretty much it. Code is here. Read the Read Me first. (The most important caveat is that the bundle is never unloaded while SystemUIServer is running.) If someone actually uses this for something useful, please tell me about it.

Edit: I thought I’d said this earlier, but apparently not: as pointed out in the comments, Alacatia Labs published the same information a week before me, and did a slightly better job too. If I had used the power of the intergoogles, I would have known that, but then I’d have missed the fun of working it out.

This entry was posted in Cocoa, Code and tagged , , , , . Bookmark the permalink.

23 Responses to The Mysteries of iCal, Revealed!

  1. Pingback: Michael Tsai - Blog - The Mysteries of iCal, Revealed!

  2. Interesting. I don’t know if you have noticed but the dock icon for iCal is not always updated. I’ve put my Macbook to sleep before the day ends and woke it up next day and it basically spent all day with yesterdays date in the icon. This is all without iCal running at all.

    Are they using a cron job of some sort to call a script to regen the icon?

  3. Pingback: Crooked Spin » Blog Archive » DockExtras

  4. Jens Ayton says:

    Looking at the class-dump, there’s a class in iCalDockExtra.bundle called CalDayMonitor, which appears to be responsible for noticing clock rollover, and another called CalSystemMonitor, which appears to be responsible for noticing clock changes and wakes. I guess the latter isn’t working for you. If you want more details, class-dump it yourself; it’s much more edumacational that way. ;-) (Oh, and consider filing a bug.)

  5. Pingback: soeren says » Blog Archive » Leopard: Updating Dock icons of non-running apps

  6. Mo says:

    Nice find! I was wondering how this was done :)

    rdar://5591798 is the bug filed for “iCal icon only updates itself intermittently”; my icon shows yesterday’s date, but my computer was awake all last night and the vast majority of today (only sleeping when I was commuting to/from work). Showing the wrong date inconsistently is worse than always showing a fixed date—you’re never quite sure if it’s correct or not!

  7. Sabon says:

    What I wish is that it auto have the abbreviation for the day on the icon too. You know, Mon for Monday, etc.. It’s got room since it is using a three digit abbreviation for the month.

    Why is abbreviation such a long word when …

  8. We also posted our take on this last week. Pretty much the same conclusions. Our writeup and example is available here:

  9. Dan Corban says:

    I also had the weird issue where the dock icon would alway show yesterday’s date instead of the current date. With about 5 seconds of research, I found the solution. I have (so far) permanently fixed the problem by simply deleting, then re-adding the dock icon.

  10. neoguri says:

    I agree with Mo: not knowing whether is correct made me remove the iCal ico from the dock. And I don’t see how deleting and re-adding is a permanent fix but rather an incidental work-around.

  11. David Jones says:

    That is an interesting find, and the lack of updating is also interesting. I use MS Word a lot in my work, and it always tries to suggest (auto-fill) the date when I start typing the name of a month. Unfortunately, as was described above for iCal, the suggestion is always the date I last booted my Powerbook so not necessarily the right date. I wonder if they are calling a routine like iCal…


  12. clvrmnky says:

    @Mo: thanks for posting the bug report. I turfed iCal from my dock once I noticed it still wasn’t being updated. At least it was only a day behind now.

  13. Pingback: Apple Blog » Blog Archive » How Leopard’s iCal stays updated

  14. Jens Ayton says:

    Ben, NSDockTile is an improved interface for modifying the dock tile for a running application and its minimized windows. It doesn’t have any functionality for updating the dock tile of a non-running application, which is what the dock extra does.

  15. If I am not completely wrong, the icon always updates when restarting the computer. And interestingly enough, when you don’t restart your computer for more than a day, the icon never shows the date of any other day than the previous (and not the date of two or three days ago, as once might expect…)

  16. Something else is interesting: When you open ical on a day when it’s showing yesterday, the icon will change to today’s date when open. Upon exiting ical, the icon will go back to its previous state – yesterday.

    @Sabon: The ical icon on the iphone also shows the date, in full. There seems to be no issue with the ical icon on the iphone, btw – correct day and date show also without reboot.

  17. Jacob Hazelgrove says:

    I didn’t find this until after I had 10.5.1, but this appears to have been fixed to update when the date changes, as I can change the date on my system, and the dock icon automagically updates properly.

  18. Jens Ayton says:

    Just to be clear, the bug didn’t affect everyone on 10.5.0. It worked fine for me.

  19. Rasmus says:

    Jacob: It wasn’t fixed in 10.5.1 (since I came here googling for a fix, while running 10.5.1). Although it seems that the removing/adding the icon from the dock incidentally fixes the problem.

  20. Pingback: Ahruman’s Webthing » Blog Archive » Hacking your Crash Reports

  21. Pretty cool find! I figured they did it using the iCalHelper daemon, and then pinged the dock to reload it’s icon with an SPI but this makes it much more third-party-accessible.

  22. Prashanth says:

    Hi, I was wondering where/how the font/text of iCal dock icon is controlled and how it could be manipulated. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *