Category Archives: OS X

fortune for xscreensaver for OS X

I love that jwz ported XScreenSaver to OS X at about the same time I moved to OS X for my laptop.  I got to keep all the screen savers I use and have used over the past decade or so.  Especially some of the cooler GL based ones.  (Its also nice that someone ported rss-glx as well, but that’s a different story.)  The only piece XScreenSaver is missing is the controller to randomly call only selected hacks.  Luckily, RandomExtra fills that hole.

One issue I’ve had with xscreensaver on OS X has been the difficulty/impossibility of having the text displaying hacks use fortune (or any program, for that matter) as the source of the text.  Mike mentioned this morning that all those hacks appear to be able to call out to a URL.  This morning I felt strangely motivated, so I whipped up a quick ruby script that is basically an HTTP based fortune server.  Since ruby ships with OS X, it’ll make it easier in case anyone else wants to get it running as well.  Once I got that working, the question was how to have this launch automatically on OS X so I wouldn’t have to worry about it.  I’ve played with Lingon on and off, and it seemed like the tool to help me do it.  I used Lingon to create a UserDeamon that should launch when one logs in, and should die when one logs out.  I then went through the screen savers that call out to text and pointed them at the localhost URL, and boom, I was back to fortune city.

To recreate this you’ll need this fortune_helper.rb script I whipped up, Lingon to create the launcher or this fortune.plist (put in /Library/LaunchDaemons) and fortune installed somewhere.  I installed fortune via DarwinPorts.

OS X moving unix forward

For every stupid hard coded Steve Jobism in OS X1, there’s some really awesome unix extentions I’d like to see elsewhere.  The big one for me today has to do with DNS handling.

I’ve been playing with OpenVPN to get access to my network at home.  Since I have a MacBook Pro from work, that’s been my end point client.  I’ve been using Tunnelblick as my OpenVPN client to connect to OpenVPN server on my linux box (installed via DAG’s RPM repository.)  One thing that bugged me was how to get DNS so I can see my internal home DNS without breaking access to work’s internal DNS.  If I was using a linux laptop, I think my solution would have to do with running a local instance of named with some wacked out config to do caching only and refer to different DNS servers.  Hardly dynamic and a giant PITA to get going.

I was curious about how to make this go though, and what general solutions people had when I came across a post by Mike Erdely titled OpenVPN + DNS + OS X.  That is exactly what I wanted to do!  As a bonus he’s even using Tunnelblick.

Mike shows how OS X’s DNS resolver uses an /etc/resolver directory to get additional per-domain configuration information, as opposed to the blanket /etc/resolve.conf that unix users have come to know.  To get the mac to resolve kgarner.com using my doman’s internal DNS server I just need to create /etc/resolver/kgarner.com and put nameserver 192.168.1.10 inside of it.  This directs OS X’s resolver to ask 192.168.1.10 for any kgarner.com query.  He also shows how to flush OS X’s DNS cache via lookupd so if I had hit any of my public kgarner.com IPs the resolver will send me to the private ip instead of the public one i’ve already hit.  There’s also two simple scripts that you can integrate with OpenVPN to add and remove the /etc/resolver entry as needed.

The fact that OS X’s resolver will check for entries /etc/resolver first is the type of smart unix extentions I’d like to see more of.  There’s no reason Linux’s resolver can’t be doing something like this.  It would make VPNs easier to implement, and doesn’t seem to be that hard to add to the resolver code.

Other examples of OS X moving stuff forward is the init/cron/at all in one launchd.  I’m slowly starting to agree that init, cron, and at are all sides of the same coin.  Don’t get me wrong, launchd has some issues, but the idea is a step in the right direction, especially for machines that will sleep.  A lot of what OS X has done to make unix better is especially for mobile sleep-capable devices like laptops.

1 Ask MARK for a laundry list of them…  🙂 

Stupid Finder tricks

As a unix geek, I like to see and sometimes browse /usr for various reasons.  While I can do it from the command line, it would be nice to be able to do it in the Finder.  Thanks to information I found in the article Top Ten Mac OS X Tips for Unix Geeks I was able to make /usr not hidden anymore.  (The article is from 2002, but this bit of imformation is still relevant.)  The following command removes the HFS+ hidden attribute and that lets the Finder show it.  As the full path below implies, you need to have the developer tools installed.

# /Developer/Tools/SetFile -a v /usr

color grep

Every once in awhile I come across a feature of a piece of software, generally, a small utility that I hadn’t known about and that shows immediate value.  Today Jon showed me the --color flag for GNU grep.  It uses color to highlight the term you were searching for in the line returned.  For example:

# grep –color=auto -i metadata todo.txt
Metadata Functions to Move:
   MetadataView…Make sure only our indexed items are passed up.

Its a very simple thing, but one of those that I’m surpised I haven’t been using.  I know have a shell aliases for that.  See the grep documentation for more information.

[Update 6/2: linux.com has a great article on GNU grep’s new features which talks about the color.  One that I’m particularly expected about is the ability to use Perl-style regular expressions.]

Concatenate PDFs

I often like to print out many web pages to read on the train.  To not waste paper I like to print them 2 up and double sided.  If the printer supports it, I also like to staple the pages.  On Linux, I use Firefox to print to postscript, then used a2ps to have the PS files combined, 2-uped, and short-side duplexed.  I’d then manually staple it, as there was no good way to tell the print center at work to staple it.  I’d use a command line similar to this:

a2ps -Eps -Afill -stumble 1.ps 2.ps 3.ps 4.ps

I tried this approach under OS X, but the problem is that the postscript that is generated on OS X is so detailed that it takes forever to process to print out, on the order of 2 minutes of processing per article.  Since PDF is the spooling format for printing in OS X (coming soon to linux) I thought I’d look to see if there was an easy way to concatinate PDF files so I could then have the regular printing interface (via Preview) handle the 2-up, double-sided, stapling goodness.

After much searching around I found this article and later this web page.  Combining a bit from both, I came up with following that works really well in my few days of testing.

texexec --pdf --paper=letter --pdfarrange --result all.pdf 1.pdf 2.pdf 3.pdf 4.pdf

It runs really quickly (especially in comparison to the a2ps method) and then I just open all.pdf and print from there.  It requires that you have teTeX installed.  On both Linux and OS X I had this installed as part of the prerequesets for docbook and doxygen.

Put OS X dock into the corner

Dock pinned in corner.I recently got a MacBook Pro at work.  I’ve been slowly adjusting to OS X.  I’ll post more on the adjustments I knew I’d have to make and the ones that suprised me later.  However, I found a nick trick that took longer to find than I thought it would, so I’d blog it.

The OS X dock has its good and bad points, but its important due to that’s where minimized apps go and where running apps keep there icons.  However, by default, it is centered and that doesn’t jive with how I like to place windows.  Especially when coding.  Based on the information given here at applepedia and the definition at this O’Reilly article I was able to figure out how to put it into the lower left or lower right corner.  Click on the image here to see a screenshot of the dock put in its place.

The feature is called pinning.  Just do the following from the command line:

# defaults write com.apple.dock pinning -string start

After you restart the doc (by either logging back in or a nice "killall Dock.app" that will pin the dock to the left.  If you want to lock it to the right, switch the start to end.