Wordpress code: Find parent category of blog post

On MyBankTracker.com we introduced a new category structure. For reasons I won't get into, I needed to find the parent category of the current post's category. But, finding the parent category was surprisingly difficult using standard Wordpress functions. Anyways, this code is based on get_category_parents() which can be found in wp-includes/category-template.php. Note: this is tail recursive, so it could be rewritten to be iterative. Feel free to copy and redistribute.

Usage:

As expected, use this code at your own discretion. No support or liability implied by sharing this.

Yojimbo + Dropbox + sleepwatcher

There is a great post on the Yojimbo google group about how to get Yojimbo working on Dropbox. This allows you to synchronize your notes/passwords/etc over more than one computer.

http://groups.google.com/group/yojimbo-talk/msg/9465b1c53650a2b9

The one snag is that you can only have Yojimbo running on one machine at a time. In order to work around this limitation, I've used the command line tool sleepwatcher to monitor when a computer goes idle. I modified the example plist to configure sleepwatcher to run a script that tells Yojimbo to quit after 10 minutes of idling. 

Download sleepwatcher http://www.bernhard-baehr.de/ and follow the basic instructions in the readme.

Here are the scripts to do it.

The AppleScript code to quit Yojimbo: (place in your home directory ~/)

After installing sleepwatcher according to the readme, and creating the above script, we test to see if sleepwatcher is working correctly by issuing the following command. Make sure Yojimbo is open, otherwise it won't close.

$ /usr/local/sbin/sleepwatcher --verbose --idle ~/quit_yojimbo.sh -t 100

This should quit Yojimbo after 10 seconds. Next on to the launch agent.

The launchctl plist to run sleepwatcher on launch. (place in ~/Library/LaunchAgents/)

Note: -t is for time, which is in units of 0.1 seconds; meaning 10 minutes is 6000, not 600. To install the launch agent, run this command (note: no sudo).

$ launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist

Update: one additional side note.

If you have OS X 10.6 and Adobe products on your machine, you may see an error when running osascript for the ~/quit_yojimbo.sh script. If that's the case you can ignore the error, or follow the instructions here: http://kb2.adobe.com/cps/516/cpsid_51615.html

It shouldn't matter either way.