Reverse Keyboard Mapping AppleScript

I’ve been switching between my Macbook Pro’s internal keyboard and an external Microsoft Natural keyboard fairly regularly, so the reversed option/command key problem has been a pretty constant thorn in my side. I couldn’t get the 10.4: Change keymapping only on external keyboards hint to work (I probably just need to clear some of those kernel caches after changing the mapping), so I finally got pissed off enough to write an AppleScript to help. That way, I only need to worry about the switched keys for one Quicksilver call. 🙂

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.keyboard"
end tell

tell application "System Events"
	get properties
	tell application process "System Preferences"
		click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
		
		set commandKey to value of pop up button 3 of sheet 1 of window "Keyboard & Mouse"
		
		-- DEBUG
		-- display dialog commandKey
		
		--  Default, lets flip
		if commandKey ends with "Option" then
			-- click the pop up button menu "Option", this menu does not exist until it is clicked in the GUI
			click pop up button 3 of sheet 1 of window "Keyboard & Mouse"
			-- click "Command" of the pop up menu
			click menu item 4 of menu 1 of pop up button 3 of sheet 1 of window "Keyboard & Mouse"
			
			-- delay briefly
			delay 1
			
			-- click the pop up button menu "Command", this menu does not exist until it is clicked in the GUI
			click pop up button 4 of sheet 1 of window "Keyboard & Mouse"
			-- click "Option" of the pop up menu
			click menu item 3 of menu 1 of pop up button 4 of sheet 1 of window "Keyboard & Mouse"
			
			-- Not Default, lets flip it back
		else
			click button "Restore Defaults" of sheet 1 of window "Keyboard & Mouse"
		end if
		
		-- click "OK" to dismiss the sheet
		click button "OK" of sheet 1 of window "Keyboard & Mouse"
		
	end tell
end tell

tell application "System Preferences" to quit

As always, looking up what objects/properties to call is suitably obscure, but I think I’m getting better at this.

A CFL in every Home = 1 Nuclear Power Plant

I spent a lot of my weekend doing research on energy, power generation, etc. (See my MyWeb links) I decided to run some rough numbers, and have come to the conclusion that the best use of government funds is to probably have a CFL handout/trade-in program.

There are an estimated 110M households in the US, so if you replaced one 60W incandescent with a similarly lumen-rated 13W CFL (I’d estimate a distribution cost of $100M-200M), you’d save just over $4.1B in electrical bills over the lifetime of the bulbs ($0.10/kWh over 8000 hours). At 5 hours/evening of usage (~4.4yr), we’re looking at almost a billion bucks a year. That’s not a bad ROI.

Another interesting figure that comes out of that is that we’re talking about a significantly large amount of power saved. Over the bulb lifetime, the number comes out to over 41M MWh, or based on the 4.4y estimated lifetime, about 9.4M MWh/yr. That’s more than your average 1000MW nuclear power plant will be able to generate (about 7.8M MWh at 90% efficiency), and a significantly lower cost ($10-20/MWh for handing out light bulbs versus $50-80/MWh).

So, for every incandescent light-bulb replaced in every household in the US, you’re replacing the need for a nuclear power plant (or better yet, a bunch of fossil fuel ones ones, which function at a much lower efficiency (around 60%) and are usually lower capacity).

Why You Should Always Run the Numbers

We interrupt our normal (very) irregular postings on Web, Tech, Music, and Politics to talk about the exciting world of Personal Finance!

Having spent my years at USC faithfully saving into my 403b, I wasn’t planning to put anything more into “retirement” – based on my calculations I’d already reached my >60 goals (such is the power of a 2:1 to 10% match and the power of compound interest).

Boy am I glad I stopped and ran the numbers on what the difference is for contributing to a 401k vs regular investment. Here are some notes on calculating benefit even if you plan on withdrawing before retirement (basically, using the 401k as an investment vehicle):

  • Because the 401k is invested pre-tax and is treated as regular income on withdrawal, even after the 10% early withdrawal penalty, you’ll start off with a 1-2% bonus (the exact number depends on your marginal tax rate vs your capital gains)
  • If you further assume a drop in tax bracket, say from the maximum 35% at time of investment to a more reasonable 28% or 25% for when you cash out, you’re looking at an instant bump in returns of 12.2% or 17.65%, respectively.
  • Figure in a modest employer match, say 1:4, vested at 67% (16.75% at the point of investment), and you’re up to a 37.5% returns difference. That’s not too shabby!

So far, all of this has been time-invariant (because the numbers are lopped off the bottom and top and not affecting the rate of return). However, if you’re investing in mutual funds, your difference of returns after taxes on distributions (always taxed as income) can be anywhere from about 0.5% for tax-managed and index funds, to 2% or more (my highest fund, Vanguard’s Energy Fund is there; Vanguard rates it as 50% tax efficient, so I’m assuming there are worse out there).

Now, here’s where we apply the power of compound interest. Assuming a 1% difference in tax load, even over 2 years, there will be a 2.5% difference. Over 10 years, this becomes a 12.75% difference, and over 20 years, we’re talking about almost a 27% difference. (that’s added on top of top of the existing 37.5% returns difference)

And remember, this is *with* the 10% early withdrawal penalty and paying full income taxes (vs capital gains). And that’s why you should always run the numbers.

NOTE: I’ve seen one document online that seems to imply that in addition to the withdrawal penalty, you’ll need to retroactively pay capital gains, but that seems to contradict what the IRS has to say on distributions, but it’s probably a wise idea to consult a certified tax professional for the final say on the matter (-CPA has confirmed my reading, although noted an additional 2.5% state penalty). Besides early disbursement, you can also take a 72(t) or by taking a loan out against the 401k (this only works while you’re employed).

Depressing

This is an incredibly depressing factoid.

“According to the U.S. Treasury Department, America’s first 42 Presidents, from George Washington (1789) to Bill Clinton (2000), borrowed a combined total of $1.01 trillion from foreign governments and financial institutions. From 2000 to 2006, the Bush White House has borrowed $1.05 trillion alone. Yes, that means we have borrowed in the last 5 years what we had previously borrowed in the first 211 years of our country.”

For more good stuff, be sure to check out the recently aired Frontline entitled Can you afford to retire? – the entire episode is online in streaming Real/WMP chunks.

FireBug Hidden Functionality

Joe Hewitt came on-campus today and gave a presentation on FireBug. I use Firebug all the time, but it turns out that it’s chockful of features that aren’t in the docs.

Besides using the search box to do things like filtering for event types and other strings, you can also filter by CSS selector. That’s insane – insanely useful! Also, 0.4 not only brings back copyable URLs, but also lets you launch an URL in a new tab with a CTRL/middle-click.

Joe also went through the new debugger and mentioned how to use that for conditional breakpoints.