OS X Tip: Change shell to that of frontmost Finder window

I was looking for any integration between Finder and Git (because I like GUIs sometimes. (I know about GitX.))

I came across this instead, a bash function (which works in zsh) that changes directory to that of the frontmost Finder window. It's convenient!

cdfinder() {
  cd "$( /usr/bin/osascript <<"    EOT"
    tell application "Finder"
        set currFolder to (folder of the front window as alias)
      on error
        set currFolder to (path to home folder as alias)
      end try
      POSIX path of currFolder
    end tell

Reference: asktherelic.com/.../osx-terminal-and-finder-integration/

pylibmc 0.9

A big hand goes out to me. And not for releasing a new version of my own software, but for forgetting to tell anyone about it!

pylibmc 0.9.1 adds a get_stats method, some more compatibility niceness, and the most oft requested feature: per-error exceptions.

Get it while it's hot! Wait, right, I missed my release announcement.

And this is what I mean by "per-error exceptions":

>>> import pylibmc
>>> mc = pylibmc.Client([""])
>>> try:
...   mc.incr("boegen", 123)
... except pylibmc.NotFound, e:
...   print "Oi!", e
Oi! error 16 from memcached_increment: NOT FOUND

MacBook Multitouch - in Python

I's gone an' outdone myself! Since the last post got so much attention, I realized more people were interested in reading the touch input than I thought.

So, I wondered how good ctypes is at using private frameworks from Apple. Turns out, pretty darn good.

This is an implementation of a simple multitouch listener which just prints the information:

def my_callback(device, data_ptr, n_fingers, timestamp, frame):
    print device, timestamp, frame
    for i in xrange(n_fingers):
        data = data_ptr[i]
        d = "x=%.2f, y=%.2f" % (data.normalized.position.x * 100,
                                data.normalized.position.y * 100)
        print "%d: %s" % (i, d)
    return 0

devices = MultitouchSupport.MTDeviceCreateList()
num_devices = CFArrayGetCount(devices)
print "num_devices =", num_devices
for i in xrange(num_devices):
    device = CFArrayGetValueAtIndex(devices, i)
    print "device #%d: %016x" % (i, device)
    MTRegisterContactFrameCallback(device, my_callback)
    MTDeviceStart(device, 0)

# Why sleep instead of join? Ask David Beazley.
while threading.active_count():

See this paste for the whole body, including the ctypes definitions and mappings.

I also wondered how good pygame really is, so I decided to try it out. See this paste for the pygame-based thing. It uses only the SDL bindings, no SDL_* extras. To quit it (it's fullscreen), hold one finger still and swipe four fingers quickly downwards.

Multitouch on Unibody MacBooks

A little known fact about the unibody touchpad is that it can distinguish between up to eleven touch points - i.e., fingers.

Another little known fact is that the sensor knows about the contact surface area (in terms of ellipsoids).

Another yet less known fact is that Johan Nordberg didn't sleep much last night, and wrote a neat OS X application which simply plots what the trackpad (or Magic Mouse!) is saying about touches.

Download blä.se/FingerMgmtUB.zip to try it out.

Update: Apparently works on older MacBooks as well! Give it a shot, it might be your lucky day.

RSS 2.0