Software Development

Wicked Hacks for your Mac

I’ve been using a Mac at work for the past few months. It’s refreshing.

My first computer that was actually my very own computer was an iBook (G3) back in 2003 or so. I loved it. I downloaded all kinds of software to make it do interesting things (or do boring things in interesting ways), and when I ran out of things to download I fired up Applescript Editor and wrote some myself.

Having not used a Mac regularly for a few years, I was a bit curious to see how quickly I would get back to my old ways when I was put on an iPad project. The answer: not long.

I thought it might be fun to share my setup in case some of these tools are useful to anyone else. For posterity, I’m using Snow Leopard on a Mac Mini, with a standard Apple keyboard and a Magic Mouse. (Lion and a touchpad should work just as well.)

Let’s start with the easy stuff.

Even without any mucking around, OSX is somewhat configurable. One of the first things I did on my new office Mac was re-map the Exposé hotkeys.

The default function keys are nice, but on the keyboard accompanying my Mini, I have to hold down the Fn key before hitting F11 to reach Show Desktop. This is annoying; I use that functionality all the time, and those keys are on opposite corners of my keyboard. System Preferences to the rescue:

By opening System Preferences, then Exposé and Spaces, you can re-wire the hotkeys for Exposé settings.

I use Right-Command, Right-Control, and Right-Shift for All Windows, Application Windows, and Show Desktop respectively.

Another big one is Hot Corners. A lot of people like to map Exposé-type actions here, but I prefer screen-related actions. The only one I have set right now is my top-right corner, which puts the entire display to sleep.

That’s not all a vanilla install can do, either. Check out System Preferences > Keyboard and Mouse > Keyboard Shortcuts for more options.

Hide and seek.

Hide is my favourite feature of OSX. In any application, press Cmd+H and the app will disappear. This is not the same as minimize, which eats valuable Dock-space; hide causes all application windows to completely vanish. To access a hidden application, either re-launch it or cycle to it using Cmd+Tab.

That’s good already, but for applications I use all the time, I like to have a single, global access shortcut. What I want is to hide the app if it is open, and bring it back into view if it’s hidden. I do this with a handy Applescript that looks like this:

if application "Application" is frontmost then
    tell application "Finder" to set visible of process "Application" to false
    tell application "Application" to activate

Replace “Application” with the name of whatever application you want to show/hide, and voilà! You’re all set!

Well, almost. We still need a way to bind that script to a single action. Now how are we going to do that?

Enter BetterTouchTool.

BetterTouchTool is a shareware application that adds improved touch events to OSX. It works beautifully with my Magic Mouse, and I’ve heard it’s just as useful for trackpads on all flavours of Macbook.

That show/hide script is one use, but I have others set up as well:

  • Two-finger swipe up: Home (scroll to top of page).
  • Two-finger swipe down: End (scroll to bottom of page).
  • Two-finger tap: Show/hide Mail.
  • Three-finger tap: Show/hide iCal.
  • Two-finger click: Zoom (the green button in OSX window toolbars).
  • Three-finger click: Launch Divvy.

In general, I like to give mouse actions to tasks that will be followed by more mouse actions. For example, I also have a show/hide script for Skype, but I’ve mapped that to a keyboard shortcut; I’m going to be typing as soon as I get into Skype, so I might as well use my keyboard to get there in the first place. For apps where I tend to be more mouse-focused, like Mail and iCal, it makes more sense to access them from my mouse.

I’ll also re-map actions that I find hard to use. That zoom button is pretty out of the way, a two-finger click anywhere on the screen is much nicer. Same for Home/End, especially since I generally scroll with the mouse anyway.

Divvy is another obvious candidate for a mouse-based trigger. If you’re unfamiliar with it, go check out what it can do — it’s a great tool for managing window sizes/locations.

Bring on Quicksilver!

Quicksilver is easily my all-time favourite OSX application. I use it constantly, and it’s the very first thing I installed when our IT guy dropped off a Mini at my desk.

I could write an entire ebook about why Quicksilver is the best thing that’s happened to MacOS since the transition to OSX, but I’ll stick to two main bullet points describing what QS is:

  1. A keyboard launcher.
  2. A trigger-management tool.

That first point is boring and I’m not going to cover it. There are plenty of other keyboard launchers out there, and they all work about the same way as far as “opening applications with your keyboard” goes.

Now triggers, that’s where things get interesting.

Like BetterTouchTool, Quicksilver lets you run scripts and other actions when “something happens”. In this case, something happening can be as simple as a hotkey being pressed, but plugins for QS add many more interesting possibilities. (We’ll get to my favourite shortly.)

I’m going to start with my hotkey setup. As I hinted at already, I have one of my show/hide scripts bound to Skype. I trigger it with F6. I find this is really useful for “peeking” at Skype to see if any important IMs require my attention — one touch to bring it up, another to dismiss it, and my tab order is unaffected.

I’ve also mapped some hotkeys specific to iOS development: I’m such a fan of Cmd+Ctrl+Up Arrow and Cmd+Ctrl+Down Arrow (for switching between .m and .h files) that I’ve set application-specific hotkeys in XCode and the iOS Simulator to switch between one another on Cmd+Optn+Ctrl+Up Arrow and Cmd+Optn+Ctrl+Down Arrow.

I have another app-specific key binding on my iOS Simulator: I’m working on an iPad application that requires login on start-up, and a while back they changed the default user’s password from “jones123” to “Oncologist”. I don’t know about you, but I can’t reliably type Oncologist (case-sensitive!) when I’m half-awake at the tail end of a twelve-hour day. So, I scripted it:

tell application "System Events" to keystroke "Oncologist"

This simple script fires whenever I hit Fn+Enter inside the iOS Simulator. It’s immensely convenient, and much faster than typing myself (even if you don’t count the time wasted when I don’t get it right).

I’ve also added a global hotkey to trigger screen lock. Quicksilver provides some convenient options for hotkey events, and the one I used here was the “Hold for” modifier. Now, when I hold Esc for a couple of seconds, QS fires a call to OSX’s built-in screen lock. It’s a little finicky, and my real usage is more like “mash Esc for a few seconds”, but hey, it’s a throwback to how I use vim :)

Ready for something a little more novel?

The magic word.

Abracadabra is a Quicksilver plugin that lets you activate triggers by drawing custom shapes on the screen with your mouse pointer. Sound a bit crazy? It is. And really useful too! This is much better explained with video, and fortunately there’s an Abracadabra screencast you can check out to see it in action (along with how to install it).

I have a couple of simple drawing gestures in place to control system volume: A straight line up for louder and a straight line down for quieter. I’m also a total neat-freak when it comes to my Downloads folder. I clear it out several times per day, and using Abracadabra, I trigger a purge by drawing an X on-screen. It’s super-cool!

Here are the scripts if you’re curious:

set currentVol to (get (output volume of (get volume settings)))
set volume output volume (currentVol + 10)

set currentVol to (get (output volume of (get volume settings)))
set volume output volume (currentVol - 10)

set pathToDownloads to "~/Downloads"
set pathToMailDownloads to "~/Library/Mail Downloads"

tell application "System Events"
    set filesInDownloads to every disk item of folder pathToDownloads
    repeat with eachFile in filesInDownloads
        delete eachFile
    end repeat
end tell

tell application "System Events"
    set filesInMailDownloads to every disk item of folder pathToMailDownloads
    repeat with eachFile in filesInMailDownloads
        delete eachFile
    end repeat
end tell

For the music lovers…

iTunes is heavily scriptable. Back on my iBook, I had all kinds of scripts wired up to Abracadabra for changing tracks, toggling shuffle, and all sorts of other functionality.

But lately, I’ve moved to Grooveshark.

Since Grooveshark is a webapp, it’s not very accessible to Applescript or apps like BetterTouchTool and Quicksilver. It also slows Safari to a crawl.

These issues can be solved by running Grooveshark in a single-site browser. I’ve taken a liking to Fluid.

Now that Grooveshark is running in its own application space, we can do all kinds of neat things to it. For now, I’m content with only a couple of scripts:

As you might expect, I have a show/hide script set up for it. This one is triggered via Abracadabra (I invoke it by drawing the musical sign for a flat). I also have a play/pause script, again triggered by Abracadabra, this time with a horizontal line (the fastest, easiest thing to draw).

I tend to stick to Abracadabra for music-related actions; it’s a bit of a tradition as this is what I used Abra for on my old iBook. Hotkeys, BetterTouchTool events, and any other action that lets you run an Applescript will work just as well.

Talk like a duck.

Lastly, you may have noticed a tweet I sent out the other day about Adium and Growl. Here’s a longer description of that hack:

If you use Adium (and you should, it’s a fantastic multi-account IM-chat app) you can have Growl deliver your notifications. This will put little, unobtrusive pop-ups on your screen, alerting you of Adium events. New messages, contacts going online/offline, that sort of thing.

Adium’s notifications are highly customizable, and likewise for Growl. Better yet, Growl provides a number of different formats for its messages. Most are visual, but I recently noticed there’s one called “Speech”.

If you open System Preferences > Growl > Applications > Adium > Configure and set the Display Style to Speech, Adium’s notifications will be read to you, out loud, in a default OS-system voice.

I absolutely love this for message alerts when Adium is not in focus. I can continue to wrap up what I’m doing, half-listening to whatever Growl is reading out. This allows me to judge whether the incoming IM is worth interrupting my current task for, and if it isn’t, I can just keep on working.

I’ve only had it live for a few days, and of course this kind of behavior will get spammy if you don’t wear headphones regularly or you get a ton of IMs from Adium, but I get downright giddy every time it goes off.

The scripts.

I can’t give you a download that will set up Quicksilver, et al. for you, but I can hook you up with a convenient zip of the various scripts I’ve mentioned above.

(I’m not providing a license; they’re a gift. Use them however you please.)

What are your hacks?

Now it’s your turn to share.

I’d love to hear what you’re doing to optimize your environment. Do you use any of the hacks above? What else are you fond of? Am I overlooking anything especially awesome?

Happy hacking!

3 replies on “Wicked Hacks for your Mac”

BetterTouchTool is note shareware, it’s more like donationware. It’s free and does not expire or anything fishy like that. You can support the developer by either donating via paypal or simply buying his BetterSnapTool app in the mac app store.

Lion users beware though, I’ve experienced performance issues using it on MacOS 10.7. BetterSnapTool seems to work fine though.

I’m curious to know why you don’t use keyboard shortcuts with Divvy? I find using the mouse painstakingly long and imprecise, and don’t get me started about the touchpad (with Divvy).

The way I have it set up is:
Shift + Command + Space -> Bring up Divvy
1 -> Left half
2 -> Right half
3 -> 2/3 Left
4 -> 1/3 right
M -> Whole screen

Leave a Reply

Your email address will not be published. Required fields are marked *