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.
Pingback: Michael Tsai - Blog - The Mysteries of iCal, Revealed!
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?
Pingback: Crooked Spin » Blog Archive » DockExtras
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.)
Pingback: soeren says » Blog Archive » Leopard: Updating Dock icons of non-running apps
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!
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 …
We also posted our take on this last week. Pretty much the same conclusions. Our writeup and example is available here:
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.
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.
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…
Look at this:
@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.
Pingback: Apple Blog » Blog Archive » How Leopard’s iCal stays updated
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.
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…)
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.
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.
Just to be clear, the bug didn’t affect everyone on 10.5.0. It worked fine for me.
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.
Pingback: Ahruman’s Webthing » Blog Archive » Hacking your Crash Reports
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.
Hi, I was wondering where/how the font/text of iCal dock icon is controlled and how it could be manipulated. Thanks.