Hot on the heels of the 1.1 bug fix release comes version a freshly rewritten 1.2 with API cleanup, bug fixes, and a great new feature.
Lately, I’ve been using observers to allow an object to observe changes to its own properties. This means I don’t have to override the setter method (I’m using synthesized properties) and the observation is managed the same way that it would be externally. The current KVO implementation (at least, in non-GC land,) however, doesn’t allow you to remove observations from yourself in your -dealloc method. This is due to the way KVO works, by interposing a KVODeallocate function before your -dealloc method. It expects that all observers of the object have been removed at this point, and warns if they are not. This is, of course, blindingly annoying — you now have to create a method that gets called on your objects by their owner before they dealloc so that they can remove their observers.
To fix this, I’ve done a little interposing of my own, putting in another dealloc method before KVODealloc that will remove self observers and call a -KVODealloc method on the deallocating observer object before KVODeallocate is called. If you don’t want automatic removal, simply return NO from +automaticallyRemoveSelfObservations on the class of your choice.
The new updates are in SVN at http://svn.shiftedbits.org/public/KVOAdditions/trunk and tagged at http://svn.shiftedbits.org/public/KVOAdditions/tags/1.2
(more…)
Leopard brings new APIs at the CoreGraphics layer to gather information about windows on the system. These functions let you find windows relative to a known window, find all windows on the system, including those offscreen, and obtain images of one or more windows as composited by the Window Server.
However, these API’s have an interesting peculiarity: when the documentation says “a CFArray of CGWindowID values” they mean a CFArray of uint32s, not CFNumbers as programmers familiar with CoreFoundation might expect. This holds true for the CGWindowListCreate(), CGWindowListCreateDescriptionFromArray(), and CGWindowListCreateImageFromArray functions, but the two functions that return window information (CGWindowListCopyWindowInfo() and CGWindowListCreateDescriptionFromArray()) wrap all numeric values in CFNumbers.
To create such an array, you’ll have to create it with CFArrayCreateMutable(), such as the following:
/* Make an array with no callbacks */
CFMutableArrayRef windows = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
/* myWindow is a NSWindow */
CFArrayAppendValue(windows, (void *)[myWindow windowNumber]);
To get the CGWindowID of a NSWindow, you’ll want to use -[NSWindow windowNumber]. Even though the documentation specifies that this isn’t the same number as assigned by the WindowServer, it turns out that it works fine with the CGWindow* APIs.
The Time Machine application, when in the dock, enables access to functions for showing Time Machine, backing up now, stopping an existing backup, browsing other Time Machine disks and showing Time Machine preferences. If you’re like me, you’d like access to these features without the app in the dock; unfortunately, you can’t — by default.
I’ve done a bit of digging and was able to implement all but one of these features in a menu extra. Download it and the source here.
And yes, the menu icon doesn’t scale nicely :)
So Time Machine is a pretty convenient way to backup your machine, and I use it to backup my laptop to an external FireWire drive. Although Time Machine backs up the “whole system,” I assumed there had to be some exclusions, such as cache files or /dev, for example. After a short bit of digging, I discovered that these paths are specified in a standard property list at /System/Library/CoreServices/backupd.bundle/Contents/Resources/StdExclusions.plist
The full list is some 57 items, and is available below. Besides the expected cache items, the list includes some items I thought interesting:
/home
*/Library/Logs
/Users/Guest
/Library/Safari/Icons.db
/.Spotlight-V100
Of these, the only one I find odd is the exclusion of logs. If your system goes haywire such that you restore it completely from a backup, it might be nice to see what went wrong.
[Update] Fixed the path to the StdExclusions.plist file.
(more…)