(((1 << 3) & (~0xF | (3 >> 1) & (~0xFFED << 4))) | ~(7 + 0xDEADBEEF << 7) >> 5) >> 5 ^ (0xDE ^ (~0xF32 >> (5 | 74 >> 2)))

Time Machine: Switching Computers

Devin Lane | Leopard | Friday, September 19th, 2008

My main Mac is out of service for a few days as the screen gets replaced, so I performed a Time Machine restore onto another computer to use in the meantime. I’ll let this computer continue backing up to the same time machine volume, then do a TM restore back onto my main machine when it’s fixed.

On the temporary machine, Time Machine didn’t want to continue backing up to the same backup folder. From Time Machine’s perspective, this is a different computer and so it creates a separate folder to perform the backups in. The MAC address of the computer is set as an extended attribute (xattr) on this folder so TM knows which folder to use.

Allowing the temp machine to use the old machine’s backup folder is simple, but not as easy as it should be. The goal is to put the temp machine’s MAC address in the place of the original’s in the xattr on the backup folder. However, using xattr -w com.apple.backupd.BackupMachineAddress 00:00:00:00:00:00 doesn’t work. Instead, you need a little program that can write the address using the xattr API.

I’ve written a little program that performs the switch. It turns off acls on the backup volume, sets the new xattr, logs the old MAC address, then turns the acls back on. You’ll need to run it with root privileges.

It’s available here, or in svn at http://svn.shiftedbits.org/public/backupswitch/trunk.

Key Value Observing Improvements v1.2

Devin Lane | Leopard, Programming | Wednesday, September 3rd, 2008

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 CGWindowList* APIs

Devin Lane | Leopard, Programming | Thursday, November 8th, 2007

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.

Time Machine Menu

Devin Lane | Leopard, Programming | Thursday, November 1st, 2007

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 :)

Time Machine Exclusions

Devin Lane | Leopard | Wednesday, October 31st, 2007

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…)

Powered by WordPress | Theme by Roy Tanck, modifications by Devin