Archive for the ‘Mac OS X’ Category

Replacing AppleScript with Ruby

Thursday, May 29th, 2008

I had a brief run-in with AppleScript trying to overcome an OS X terminal bug.  and its not something I enjoyed.  I would much rather be able to do scripts like this in a language I’m more comfortable in like ruby.  I’ve known for a while that one of the enhancements in OS X Leopard is that it has native support for scripting the UI from within other scripting languages like python and ruby, however, I didn’t realize that I could drop those scripts in the user scripts folder (~/Library/Scripts) and have them available from the scripts toolbar icon. (more…)

Wireless Shenanigans

Friday, September 21st, 2007

To date, my wireless setup at home consists of 2 linksys WRT54Gs modded with the OpenWRT firmware + x-wrt (webif2) for a better web ui. One of these routers serves as my gateway/firewall and the other connects my upper floors to the gateway via WDS (basically, its only there so my Series-1 Tivo can get online as the only mod I have for it is a wired ethernet card :) I also have a server (mythtv) which connects to my gateway via an ethernet cable cleverly hidden under a rug between the living room and study. Something my wife isn’t too happy with! :)
(more…)

Camping for an iPhone

Friday, June 29th, 2007

Yes, I actually am - I think this is the first tme I have ever camped for anything. Not sure if one can call sitting in line for 3 hours “camping”, but is as close as I’ll ever come :)

For those nearby - the AT&T store on Needham St in Needham MA, only has abou 40 people in line.

Python with readline on OS X

Tuesday, January 30th, 2007

I used to have python with readline support working on my powerbook before I swtiched to a macbook. Unfortunately, I couldn’t get it working with the macbook as I couldn’t find a binary that worked with the stock os x python (these instructions no longer worked), and python wouldn’t load the binary I compiled on my own. For various reasons I need the stock os x python and can’t just install one of the new python runtimes that include readline.Fortunately I discovered the rlwrap program which allows one to run any console app with readline support ,a quick “port install rlwrap” (using darwinports) and “alias python=’rlwrap python’” and I’m back to having full readline support in my python console.

OS X Terminal bug

Tuesday, May 30th, 2006

Call me anal if you wish, but I like to have a grid of 4 Terminal windows always open, and typically I do specific things in each window so that when I want to go do that specifc thing, I just Cmd-Tab to Terminal, and Cmd-[1-4] to get to the window I want.

Normally, at work I have my laptop hooked up to an external monitor, and at home I use just the laptop screen (usually from the couch ;). Unfortunately, OS X (or Terminal) seems to have a bug in remembering window positions when a laptop switches in/out of suspend with the display layout changing (i.e. the external monitor attaches or detaches while in suspend). If you do this, you'll notice that the Terminal windows act a little wonky until you move them with your mouse (cicking in window may not activate it, scroll wheel may not work, scroll bar may not work, etc).

Needless to say, this annoyed the crap out of me, so much so that I even resorted to learning some applescript to work around the issue (maybe I'm too much of a normal coder, but applescript seems like such an ass backwards language).

Here is the script, note that I like my Cmd-[1-4] to map to a window which always has the same position on the screen (Cmd-1 always goes top left, Cmd-4 bottom right). I keep the script in ~/Library/Scripts/Applications/Terminal so that I can run it from the Script Menu in the menubar (Run the AppleScript Utility to turn on the Script Menu).

-- position grid of 4 windows to the following coords.
-- If you want a different layout, you'll have to mess with the code
-- Cmd-1: {187, 22} Cmd-2: {691, 22}
-- Cmd-3: {187,387} Cmd-4: {691, 387}
tell application "Terminal"
	activate
	set ymul to 0
	repeat with winIdx from 1 to 4
		tell application "System Events" to keystroke "" & winIdx using command down
		set mywin to window 1
		set oldpos to position of mywin
		set xmul to 1 - winIdx mod 2
		set newpos to {187 + (xmul * 504), 22 + (ymul * 365)}
		set position of mywin to newpos
		set ymul to ymul + 1 - winIdx mod 2
	end repeat
end tell