Archive for the 'Released Software' Category

AppleScript Snippet: Set spaces shortcut key to ctrl-option

Wednesday, January 30th, 2008

So yes it happened. I switched over to using Apple hardware and OS X on my primary laptop. I’ve been very happy with my iPhone. When my girlfriend decided to buy a new TV, I thought it would be nice to have a media computer of some sort to drive the 1080p display. My good friend Brian was selling a 1st-generation Intel Mac Mini (A Core Solo), so I thought, “What the hell, why not?”

Turns out Leopard is pretty cool. OS X has come a long way since I poked at versions 10.1 and 10.2 while trying to maintain the machines in the SourceForge.net compile farm. After poking around under the hood and getting acquainted with launchd while trying to get openvpn to start on startup, I realized that it really is serious Unix, that Apple has done some really neat stuff, and that it really does have a prettier face than I’ve ever seen on a Unix box.

At that point, I started seriously thinking about buying a Mac. I knew that MacWorld was coming and rumors were flying about a new ultra-light laptop, so I took a wait-and-see-attitude. After seeing that I would only want the Air in a $3000 configuration, I went and bought the MacBook that I’ve wanted since it was released: the black one.

In short: I love it and I’ve been using it enough to start to get annoyed by it. For example, by default, the Spaces preferences allow you to choose a single modifier key for moving around spaces. On Linux, I use Ctrl-Alt-Arrow to move desktops, since nothing else really uses that; it allows application bindings to shine through and continue to work.

So I started fighting with AppleScript to see if I could get it to do what I wanted. It took some frustration (most new languages do), and I will pronounce AppleScript supremely weird if not totally readable. In the end, this was what I wanted:


tell application "System Events"
	tell expose preferences
		tell spaces preferences
			tell arrow key modifiers
				set properties to {key modifiers:{control, option}}
				get properties
			end tell
		end tell
	end tell
end tell

I hope this is useful to someone. Enjoy.

Software Release: battery_status.py

Tuesday, August 21st, 2007

Annoyed that Fedora 7 doesn’t have the same CLI tools to get battery status, I coded up a little python script last night to do just that. It was a pretty straight-forward project that took me about an hour, but I was pretty happy with the end result. It reads the proper files out of the /proc/acpi/battery hierarchy, does some calculations on that data and the gives you what you really want.

You start with this:

thesis|18:46|~% cat /proc/acpi/battery/BAT0/info
present:                 yes
design capacity:         65520 mWh
last full capacity:      69150 mWh
battery technology:      rechargeable
design voltage:          14400 mV
design capacity warning: 3457 mWh
design capacity low:     200 mWh
capacity granularity 1:  1 mWh
capacity granularity 2:  1 mWh
model number:            42T5229
serial number:           35751
battery type:            LION
OEM info:                SANYO
thesis|18:46|~% cat /proc/acpi/battery/BAT0/state
present:                 yes
capacity state:          ok
charging state:          charging
present rate:            8595 mW
remaining capacity:      66620 mWh
present voltage:         16690 mV

And you get this:

Battery 0: 96.46% (0:17 until charged)

In the spirit of sharing and trying new things, I thought I would register it as Google Code project and give it away under a BSD License. It was about a ten minutes process, start to finish and now the world can have it:

http://code.google.com/p/batterystatus/

Hurray for non-scarce economics!