Category: Mac

Holding up the ⌘+Q

Something that’s been bugging me for a while now is reaching for Command+W to close an open Finder window or a tab in Firefox, and hitting that blasted Q key by accident. Well, no more, I decided!

For the uninitiated, hitting Command+Q on a Mac keyboard quits the current application – as far as I’m aware – without exception. Some applications will give you a warning that you are about to quit and you may lose unsaved data. Since Firefox introduced built-in session management so that it will fire up just as you left it, it no longer seems to warn you when you quit. Looking at about:config in one of my Firefox tabs shows browser.warnOnQuit set to true. Firefox will warn me when I try to close a window with multiple tabs open in it, but it doesn’t warn my when I hit Command+Q.

So, in trying to fix this little problem, I discovered a few ways to create helpful keyboard shortcuts and tame some not-so-useful ones.

Custom keyboard shortcuts in OS X

You can set custom keyboard shortcuts for various aspects of OS X and any of your installed applications in System Preferences – it’s under Keyboard & Mouse, and then the Keyboard Shortcuts tab.

  1. Hit the + (plus) button to begin adding a new shortcut.
  2. Select an application to customise, or let it affect all applications.
  3. Type in the Menu Title, which is the text as it appears in the menu item you’re wanting to customise. You can just switch to the application in question to check it.
  4. Hit the Keyboard Shortcut box and then do the desired key stoke you want to use for that menu item.

Now, I knew about this before and have set a couple of my own shortcuts previously. Here’s a couple of examples from my preferences:

  • In Safari, Shift+Command+S is set to Disable Styles from Safari’s Develop menu.
  • In Thunderbird, Option+Command+V is set to Paste Without Formatting.

So, it was a bit annoying to find the same didn’t work when trying to fix my premature evacuation woes in Firefox. You seem to be able to assign keyboard shortcuts to Firefox menu items, but if you set Command+Q to a menu item other than Quit, it still quits the application. You can also try setting a different shortcut to Quit (I tried Option+Command+Q), but still no joy.

Taming Firefox keyboard shortcuts with Keyconfig

There’s an extension for Firefox called Keyconfig, which remained unusable with Firefox 3 for a while. I read that the latest build now works, so I tried it, and — hey presto! — it installed. Alas, it wouldn’t override Command+Q for me. However, it did help me fix up some keyboard conflicts caused by various add-ons.

Once Keyconfig is installed, you can go to Keyconfig… under the Tools menu to see all the keyboard shortcuts that Firefox uses. Any shortcuts that are assigned to more than one action are highlighted for you. This is great for tracking down and fixing keyboard conflicts caused by some cheeky little add-on hijacking the shortcuts you’ve grown to know and love. (Yay, Shift+Command+F now opens Web Developer‘s Display Element Information tool again, instead of opening up the settings for Foxmarks!)

So, I began to assume that Command+Q is engrained into the application somewhere, possibly at the Cocoa level.

Hacking key bindings with brute force

With the help of this OS X hint and a little poking around (thanks Sean), running this in Terminal has worked for me:

defaults write org.mozilla.firefox NSUserKeyEquivalents '{"Quit Firefox"="@~Q";}'

This tells Firefox (the org.mozilla.firefox package) to use Option+Command+Q as the shortcut (keyboard equivalent) for the Quit Firefox menu item.

As with the System Preferences method above, you need to address the menu item using the text as it appears in the menu, so "Quit Firefox". To my knowledge, this technique will only work with Firefox 3, as that release was built using Cocoa.

You can customise the shortcut where my code has @~Q by using these characters to represent the desired keys:


Apparently, you can set these keyboard equivalents globally, but I decided not to do this. If you want to target a specific application in the way I have, the following may help you find out its package name:

  1. Fire up Terminal and type ps -ax | grep firefox, but replace “firefox” with the application you’re looking for. This should help you to figure out the application’s process name. For example, Firefox’s process name is “firefox-bin”.
  2. Now fire up Script Editor and run the AppleScript tell application "System Events" to get bundle identifier of application process "firefox-bin", replacing “firefox-bin” with your target application’s process name. That code goes in the top pane of Script Editor. Then hit Run.
  3. You should see the package name appear in the output pane below the script, e.g. org.mozilla.firefox.

So, as another example, running ps -ax | grep twhirl in Terminal tells me that the process name I want for Twhirl is in fact “twhirl”. Running the AppleScript tell application "System Events" to get bundle identifier of application process "twhirl" gives me the package name de.makesoft.twhirl.[SOMEHASH].

Save your head, your desk, the world!

That’s all for now. I hope this stops a few people from banging their heads on their desks!

Mac snippet solution: Quicksilver Shelf

I’ve been looking around for something that I can store little bits of text in and then easily grab them when I need them. There are a few note-taking solutions for Mac out there that would suit, but I tend to use TextMate for notes – its templates and snippets are great for the majority of what I do – fairly big chunks of predefined text. Then I stumbled across an item on Lifehacker about Quicksilver’s Shelf. I use Quicksilver for other things anyway, so I gave it a whirl.

Using Quicksilver’s Shelf

Quicksilver’s Shelf is fairly basic for text, but it suits my needs fine. To use it, you’ll need to make sure the Shelf is installed.

The notes below will guide you through setting up the Shelf. If you’d prefer a visual guide, Sherwin Techico has recorded a useful screencast showing you how to set things up.

  1. Open up Quicksilver’s plug-ins preferences and find the Shelf Module under All Plug-ins.
  2. Make sure the box next to it is ticked.
  1. Once it is installed, you may need to restart Quicksilver.

To save an item to the Shelf:

  1. Invoke Quicksilver (I use Control+Space Bar).
  2. Press the . key (period) to enter Quicksilver’s text mode.
  3. Type or paste in some text that you want to save on the Shelf.
  4. Hit the Tab key and as you begin to type “shelf” you should see the “Put on Shelf” action come up.
  1. Hit Enter and your text is saved.

To recall items from the Shelf:

  1. Invoke Quicksilver.
  2. Type “shelf” and you should see the Shelf item appear – not the Shelf & Clipboard (Catalog) entry.
  3. Press the Right Arrow key to see the items on your Shelf.
  4. Press the Tab key to select an action. for some reason Large Type tends to be the default, but as you begin to type “copy” you should see the “Copy to Clipboard” action appear.
  1. Hit Enter and the item is in your clipboard ready to be pasted out.

If you’re a Quicksilver freak, it’s definitely worth checking out some of the Shelf’s other capabilities though. Check out the item on Lifehacker about Quicksilver’s Shelf for more on that.

Deleting Quicksilver Shelf items

The one thing that I really needed to do as I was testing it out was to delete a Shelf item once I’d put it in. There’s no option to delete a Shelf item in the command window or the catalog. According to one source, you used to be able to drag your saved Shelf items off to Trash. Nope, don’t work for me. Actually, if you invoke Quicksilver, bring up the Shelf, hit Tab and select the “Open” action, the Shelf window will pop open. You can drag items from this Shelf window to Trash.

Update: Thanks to a comment from Michael, I now know that the easier way to bring up the Shelf window is by invoking Quicksilver and then using Command+Option+S. From there you can select the item you want to delete and then hit Delete or Backspace.

Code monkeys will be fine with this approach though: Find your Quicksilver Shelves in your home directory, typically in /Users/[you]/Library/Application Support/Quicksilver/Shelves. Open up the Shelf file in your favourite text editor and remove the offending dict item from the XML.

Get more from the Shelf

I might be wrong, but I get the feeling the Shelf feature has been neglected of late. It seems you used to be able to dock the Shelf to the side of your screen, which might be useful, but I can’t get that to work in the latest version. Mind you, I’m quite happy invoking Quicksilver whenever I need something.

One thing you can do to help is set up a custom trigger (keyboard shortcut) that opens up the Shelf window. To do this:

  1. Open up the Triggers preferences in Quicksilver.
  2. Hit the plus icon at the bottom to add a new trigger; select HotKey.
  3. Bring Shelf up by typing “shelf” in the “Select an item” box.
  4. In the “Action” box, select Show by typing “show”.
  5. Save that and then double click on the HotKey symbol to the right to edit the action’s keyboard shortcut.
  6. Select the “Edit” button and set your chosen shortcut; I use Control+Option+Command+Space Bar.
  1. You can then close the window and try it out.

Quick Tip: hard refresh for Firefox on Mac

Until recently, I ran Firefox on my Mac with the cache disabled because I found it annoying that my tweaks weren’t updated when refreshing a work in progress. My usual Control/Command+F5 wouldn’t work for me. Being used to Firefox on Windows, I’d often forget and find myself powering up VoiceOver.

To clarify, on a Mac, Control+F5 is not a hard refresh as it is on Windows. In the majority of cases, the Command key replaces the Control key when converting Windows shortcuts to Mac ones. For example, Control+T to open a new tab under Windows is Command+T on a Mac.

Logic dictates that a hard refresh should be Command+F5 on my Mac. Indeed, the Firefox documentation on keyboard shortcuts shows that Command+F5 should refresh overriding the cache, but that loads VoiceOver for me (OS X 10.4 or later).

The long and short of it

I now use Command+R for refresh and Command+Shift+R for when I need to do a hard refresh. As you’d expect, you can replace Command with Control for the Windows equivalent. And now I can turn my cache back on and save some time and bandwidth!

Of course, I could have set my own keyboard shortcuts! But then I’d have to set them up on all installations of Firefox I use.

Related reading

FOUC Mac: something to note

A problem with a clients’ site yesterday reminded me something… sometimes it’s not about what’s there, but what’s not there.

Simple, huh?

A client was reporting a problem where their site wasn’t displaying properly in Internet Explorer for Mac – typical! I thought it was probably a CSS problem, or maybe I’d missed a check for IE for Mac in my JavaScript.

I checked the site and it was taking pretty much exactly 3 minutes to load each page. I commented out my main style sheet and the JavaScript file. The problem was still there. Hmm…

I eventually commented out most of the head to find out that the problem was with the blank print style sheet I put in to avoid the flash of unstyled content (FOUC) in IE on Windows, at least, until I got around to doing a print style sheet.

I’m not sure how many times I’ve stumbled across and read Dave Shea’s CSS cribsheet but down there near the bottom is this:

Don’t link to empty style sheets as ‘placeholders’ for future style sheets (like handheld or print media style sheets).
Mac IE5 chokes on the empty style sheet and the page load time increases. Instead, have at least one rule (or perhaps even a comment) in the style sheet so that MacIE doesn’t choke.

Heh – a bug in IE for Mac which does not tolerate an empty style sheet, an empty style sheet being a fix for a bug with IE for Windows. Go figure!

What to do?

Well, that’s easy: follow Dave’s advice. If you’re not ready to write your print style sheet yet, just putting a comment in the file fixes this issue.

Mac in a Box

Guess what arrived at my front door at half nine this morning!

I had just been checking out Apple’s order tracking when the doorbell went. Bloody hell! It was my Mac Mini – the order tracking said it was still at Leeds airport. So, much a boyish unpacking commenced and a photo opportunity was taken.

Mac boxes: Mac Mini, wireless keyboard and wireless mouse.

I decided to go wireless. I had considered getting a DVI KVM switch to make it easy for me to use the Mac with my existing keyboard, mouse and beautiful new ViewSonic flat screen monitor, but having seen how much the switches cost, I settled for dual inputs on my monitor, stylish Mac keyboard and mouse and wirelessness.

The excitement hasn’t quite kicked in. I’ve been so busy so far this week and it’s likely to be the weekend before I get time to play. Hmmm, looking forward to getting some Tiger lovin’. Grrrr.

Welcome to Tiger, Mac OS X v10.4.

Anyway, Jo seems to have taken a liking to the new addition to the November 5th team… she says she’s going to take it to work with her.

The Mac Mini lunchbox.

So, does this officially make me a Web Design geek? I guess not – I don’t yet have an iBook that I can sit in hallways with.