I’m very aware that while many are impressed with my massive keybindings file, 99% of people who check it out shy away from ever implementing it. Even I don’t implement all of it. I thought I’d point out a few of my favorites that you can set up on their own in a more manageable way.
To use any (or all) of these:
Create a blank text file
Add a pair of curly brackets like this:
// insert your bindings here
Save the file as “~/Library/KeyBindings/DefaultKeyBinding.dict” (unless you already have one!)
Restart apps as needed for the keybindings to load
One of the keybindings that I miss the most when I’m outside of a good code editor is ⌘↩. In most editors (and first in TextMate to the best of my knowledge), hitting this combination will insert a new line after the current paragraph and jump you to it, regardless of where the cursor is in the paragraph.
I also use one with ⌘⇧↩ that will do the same, but above the current paragraph.
You can select a paragraph by hitting ⌘←, using the up arrow to get to the beginning, then hitting ⌘⇧→ and using the down arrow to get to the end. That’s horrible.
You can use ^a to jump straight to the beginning of the paragraph instead of the edge of the screen. Then hit ^⇧e to select to the end of the actual paragraph instantly. That’s much better.
If you’re me, though, you want to do that in a single stroke. This keybinding lets you select the current line/paragraph with ⌥s. If you want to make sure you get everything, including the last line break, use ⌥⇧s.
// select entire line/paragraph
"~S" = (moveToBeginningOfParagraph:, moveToEndOfParagraphAndModifySelection:, moveRightAndModifySelection:);
// select from beginning of paragraph to last character
"~s" = (moveToBeginningOfParagraph:, moveToEndOfParagraphAndModifySelection:);
Hyphenate a series of words
If you blog at all, you’re used to creating slugs (hyphenated words). If you do anything with file naming and prefer to keep spaces out of your titles, you’ve probably done this as well. This keystroke (⌘⌥⇧-) lets you add a hyphen between the next two words from the cursor, then advance so that repeated keystrokes continue to hyphenate.
// hyphenate next space and move to next word
"@~_" = (selectWord:, moveRight:, setMark:, moveWordRight:, moveWordLeft:, moveLeft:, selectWord:, insertText:, "-", moveWordRight:);
Save your spot in a text file
With two simple commands you can have a pair of keyboard shortcuts that will store the cursor position in your text so you can go and making an edit or check a reference elsewhere in the document, then jump right back to where you were. I bind these to ⌥1 and ⌥2.
This one is especially handy when working with lists in Markdown, but is good for arranging paragraphs or lines of text anywhere. With ^⌘↑ and ^⌘↓ you can move the current line of text above or below whatever precedes or follows it.
Note: this will balk if you try to move into an area with no newline where it’s trying to go. Thus, the last item in a list that’s the last thing on the page is a little problematic. Beyond that minor snag, this is something I use daily.
// move line up
"^@\UF700" = (selectParagraph:, setMark:, deleteToMark:, moveLeft:, moveToBeginningOfParagraph:, yank:, moveLeft:, selectToMark:, moveLeft:);
// move line down
"^@\UF701" = (selectParagraph:, setMark:, deleteToMark:, moveToEndOfParagraph:, moveRight:, setMark:, yank:, moveLeft:, selectToMark:);
You can always use alternate keybindings such as ^⌘j (^@j) and ^⌘k (^@k) with these. In fact, edit all the bindings to match your needs. @ is ⌘, ~ is ⌥, ^ is Control, and $ is ⇧. Knock yourself out!
I recreated most of my current GeekTool desktop in Übersicht this morning. Übersicht (which I found via Patrick Welker) is a potential GeekTool replacement which uses WebKit and Node.js to generate “widgets” on your dekstop. As far as functionality goes, it’s not much better or worse than GeekTool or NerdTool. However, being able to style widgets with HTML and CSS opens up quite a few aesthetic possibilities.
After creating my basic, boring widgets, I wanted to take a quick look at how things could be cooler in this land of CSS3. I created “Loadbar,” an animated, color-coded vertical bar that displays the 5-minute load average. It probably needs some tweaking, but I put it up on Github so others could play with it (and let me know where it’s broken).
If you’re using Übersicht, you probably know how to load a widget. If not, just download the package, unzip it, and put the “loadbar.widget” folder in your widgets location (use the Übersicht menu to “Open Widgets Folder”). More details are availabe in the README file.
A quick demo below. Given it’s a 5-pixel stripe on the edge of the screen, it’s a little hard to show well. But I tried…
Big news for everyone who entered the Delight is in the Details giveaway: Shawn has upped the number of available giveaways from three to five! So, out of the hundreds of hopefuls, here are the lucky few:
Didn’t win? Never fear, you can still get 25% off the price of the Complete Package using this link (good for one week only). Go check it out!
I detailed the open command in the last Shell Tricks post, so I thought I’d go over some tricks for doing the opposite next: closing and quitting apps.
The first thing I’ll mention is a shell script from Jon Stovell called quit. You can download it from his freeware page. It uses AppleScript (with some great logic) to “nicely” quit any application. I’ve mentioned it before, as well as tricks for adding Bash completion to it.
Second, I’ll point out my fk shell command. The first version was handy, and I made some additions shortly after. I have a new version for you today that incorporates the quit command.
First, you need the fp (find processes) command, which gives you a case-insensitive, partial title search for running processes (you can add both of these to your .bash_profile):
And here’s the revised fk command. Give it part of a process or app name and it will give you a menu of all matches (case-insensitive). Cancel the menu with “q” or enter a number. If the process is a Mac app, it will use quit, otherwise it will kill the specific process chosen.
Note that you need the quit script in /usr/local/bin (or edit the fk function to match your own location).
Now you have the counterpart(s) to OS X’s open command. Enjoy!
I mentioned a bit ago that Shawn Blanc’s book, ‘Delight is in the Details’ has recently received a big update. I’m happy to announce that Shawn is giving away 3 copies of “The Complete Kit” to BrettTerpstra.com readers. That’s the eBook, the audiobook, interviews, videos, and more ($45 US value).
Just enter a name and email below to sign up for the giveaway. Winners will be randomly chosen by the Giveaway Robot on Monday, August 18th at 12pm CST.
I’ve mentioned this before, but wanted to do an official post now that Clarify fully supports Markdown and has become a great blogging tool.
Clarify is a great tool that lets you take screenshots, annotate them, add paragraphs of text and then output to PDF, DOC, web and more. It’s designed for screen-based documentation, and I’ve always loved it for exactly that, but recent improvements have actually made it a great tool for blogging tutorials and presentations.
There are two ways you can use Markdown in Clarify now. First, you can write in Markdown right in Clarify and have it output exactly what you write. This is called “Markdown Passthru.” Second, you can write using its rich text tools and have the output converted to Markdown, ready for posting on a Markdown-based blog. It will output all of the images in the “lesson” in whatever format you need, with or without frame effects, and can output full size as well as images resized to specified dimensions. In this second option, you can also include raw markdown in your post and it will be output as written along with the converted rich text portions.
You can even customize your own Markdown output using PHP and some basic templating. For example, I have one called “Jekyll” now that outputs Liquid tags for images instead of Markdown, and moves my images into my uploads folder1. I just export using the Jekyll plugin to my “_drafts” folder, and I have a ready-to-publish post, complete with YAML headers. You can find examples of Markdown templates on the Clarify site.