Category: tips

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:

@
Command
$
Shift
~
Option
^
Control

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!

Quick Tip: speedier PHP/CSS commenting

Continuing in the vein of “the obvious ones are often overlooked,” here’s another quick productivity tip!

When you want to type a comment in a PHP or CSS file, speed things up a little by using the / and * keys on the numeric keypad. On (most) laptops, hold down the Function (Fn) key to access the overlaid numeric keypad.

Back when I used to use a full-size keyboard, I would use the / and * keys on the numeric keypad to quickly insert comments into my PHP or CSS. It was so much quicker than using / and Shift+8 keystrokes.

When problems with RSI last year encouraged me to switch to using a compact keyboard, I missed that shortcut. However, I quickly realised that I could hold down the Function (Fn) key on my new keyboard to quickly access the overlaid numeric keypad.

I recently bought myself a MacBook Pro and have just figured out that I can do the same thing. Holding down Function (Fn) allows me to access the numeric keypad and my quick way of typing comments. Yay!

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

Removing alt tooltips in IE with JavaScript

There was a bit of debate on Anne van Kesteren’s blog last year about alt attributes being rendered as tooltips by some Windows browsers, most notably, Internet Explorer.

Following the W3C specifications, there’s no reason for alt attributes to appear as tooltips. However, there’s nothing to say that ‘alt tooltip’ behaviour is wrong. Certainly, alternative text should appear if an image does not render on the page.

Working on a recent project, the client asked why the descriptive alternative text for an image appeared when they moused over the header image that spanned the top of each page of content. They wanted the alternative text to either not appear or be set to text optimised with keywords.

Update: When first writing this article I was under the impression that screen readers would announce all images followed by their alternative text. Consequently, I’d put alternative text in for all images in markup because I’d personally prefer to be told, “Hey, this image is of an old oak tree with twisted branches” than “There’s an image here, but we don’t want to tell you what it’s in it”! I’ve since found out that JAWS will not even announce the presence of an image that has an empty alt attribute. If that behaviour can be relied upon in all screen readers, the most appropriate solution to our problem may have been to leave the alt blank. I think the JavaScript solution I provide below is still useful should you wish to get Internet Explorer to present correct tooltip behaviour.

What could we do?

The alt text was fit for purpose and we refused to bend the rules for the sake of a bit more SEO. So, we wanted to keep the alternative text but override the tooltip behaviour in Internet Explorer.

Setting an empty alt would have removed the tooltip, but at the expense of accessibility. That’s the obvious option out the window.

Before I go any farther, I thought I’d better point out that alt attributes are a good thing and are required for all images in markup. If you are reading this thinking otherwise, I highly recommend that you read up on appropriate use of alt attributes.

Another option was to add the image as a background with CSS, as it could have been considered a decorative image. Being so close to project finish, we didn’t want to have to go through the site making all the images backgrounds. We also wanted these images to stretch with increases in text size. Next option down.

Internet Explorer will correctly display the contents of a title attribute as a tooltip when one is set on an element. Rather conveniently, an empty title attribute overrides Internet Explorer’s ‘alt tooltip’ behaviour but does not show a tooltip. However, we can’t be sure this will happen in all browsers and I don’t like to muddy my markup.

We opted for an unobtrusive JavaScript solution. This keeps the solution in the behaviour layer and allows us to sniff out Internet Explorer.

Enter the JavaScript

I came up with two JavaScript solutions:

  1. Using mouse events for the image: when onMouseOver is triggered, swap out the existing alt text and set the alt to an empty string, then reinstate the original alt text when onMouseOut is triggered.
  2. Override the tooltip that appears as a result of the alt text by ensuring a title attribute is set on the image — an empty title attribute doesn’t display a tooltip in Internet Explorer, but does override the ‘alt tooltip’ behaviour for us.

The latter was preferential as it didn’t seem to have any immediately obvious accessibility issues.

A bit of a disclaimer: I don’t recommend overriding any behaviour unless you really have a need to do so. I used this solution in a selective manner. If you intend to use JavaScript to override behaviour in any significant way, consider providing client-side options so that users can set a preference.

So, without further ado, here’s the code I used. Feel free to use it, share it, suggest improvements or provide your insight on tooltips displaying alt text.

var objFixIeTooltip = {
	// methods
	init : function() {
		// detect support
		if (!document.getElementById || !document.getElementsByTagName) return;
		// detect IE - leave out if using conditional comments
		var isIE = navigator.userAgent.indexOf("MSIE");
		if (isIE < 1) return;
		// find the image(s) - tweak to your needs
		var elContainer=document.getElementById("header");
		if (!elContainer) return;
		var elImg=elContainer.getElementsByTagName("img")[0];
		if (!elImg) return;
		// if there isn't already a title attribute set on the image, set the title attribute to blank, thus overriding the alt tooltip behaviour
		// use == '' because IE always thinks title is a string (cannot distinguish between undefined and empty attributes)
		if (elImg.getAttribute('title') == '') elImg.setAttribute('title','');
	}
};
addLoadEvent(objFixIeTooltip.init);

Of course, to avoid using browser detection within the script, you could leave it out and include the script using conditional comments:

<!--[if IE]><script type="text/javascript" src="path/fixIEtooltip.js"></script><![endif]-->

References and reading

On alt tooltips:

On alt attributes and alternative text:

You can find more on alt attributes and alternative text in my del.icio.us bookmarks.

And just for fun – I love this: Wheee!

vCard Tools in Mozilla Thunderbird

I’ve just discovered the MoreColsForAddressBook extension for Thunderbird.

It’s not obvious from its name, but it provides import/export tools and additional entries for contacts in your Mozilla address book, which includes really useful operations that support vCard! This makes a great companion for those of us who use the vCard format to share our contact details with the world.

The extension doesn’t appear to be listed in Mozilla’s add-on repository, so I thought it was worth giving this an airing here. Read more about this extension on its page: MoreColsForAddressBook

The Manage-Do Flipbook

There have been a few bloggings recently discussing techniques for organising yourself and your projects, so I thought I’d share the system I’ve been using for the last couple of years.

In summary, it’s just a flipbook that you use like this:

  • Brain-dump your tasks into your “inbox” in one side of the flipbook.
  • Manage your tasks daily, prioritising the tasks in your inbox and writing them into the other side of the flipbook.
  • Do the tasks in your flipbook, ticking them off as you go.
  • Revel in the feeling of triumph when you finish your tasks for the day; success in the face of chaos!

A Little Inspiration

During my final year at university, my project supervisor was really interested in different techniques for self-organisation/life hacks/whatever you want to call it. He was reading David Allen’s Getting Things Done and applying some of the principles himself. He would always have his “inbox” folder with him, which was somewhere to put things as they came to him, whether it be a report or a quick note on the back of a napkin. Items in this folder would get sorted periodically and either filed, actioned or put aside for later.

He also mentioned that keeping your inbox as empty as you can was a good way to stay on top of things. Likening this to an e-mail inbox: the e-mails that you can handle straight away, handle them – others, file appropriately.

When it comes down to it, organisation is subjective. What works for one person won’t work for another. On the other hand, some people are just beyond help. =) Anyway, I want to share how I used these ideas to come up with a system that works quite well for me.

The Manage-Do Concept

Undertaking a project on your own, you find that you take on two roles. Half the time you’re a project manager, figuring out what needs doing and when. The rest of the time you’re a worker, doing the actual tasks involved in order to reach the desired goal.

My flipbooks.

Realising this gave me the idea of using a flipbook (like your typical policemen’s flipbook) to organise myself – not just my projects, but pretty much everything. No matter how hard you might try to separate work and home life, the two are always merging – especially if you’re self-employed. You might suddenly think that you need to pay the gas bill during your lunch break. Or you might come up with that killer new software feature when you’re putting your laundry in the washing machine. Having one book like this makes sense and takes up less space in your pocket.

I use my flipbook in both directions. I go through the book in one direction for managing things and in the other direction for doing things.

Da Management

This is my “inbox” for things: the “manage” side of the book. It’s a big waiting list of things I need to do with one item per line and space at the end of the line to tick each one off. Some things I find useful to break off into dedicated inboxes. For example, I have a “people” inbox for those things I need to remember when I bump into someone or when e-mailing. Another example might be to have an inbox for contextual aims, like things I’d like to get done when I’ve got a spare moment and a piece of paper handy.

Together, these inboxes form my organisational aims at the highest level. Sometimes specific tasks will find their way in, but in general, these are aims rather than objectives.

I regularly attend to these inboxes and plan the next couple of days. I figure out what I need to get done and when I am likely to be able to do them. As I have a general overview of things in the manage side of my book, I can prioritise and order tasks to best suit the next day or the week ahead. I list activities for each day in the flip-side of the book: the “do” side.

Do the Do

As with the manage side of the book, each activity has one line with space to either check it off as done, mark it as “postponed” or “will do later”, or cross off completely. I sometimes also add context to an activity. For example, it can be useful to list several things I need to do while I’m at an Internet connection.

If I’m honest, I don’t always stick to the plans I make, but the system is flexible enough to handle when things don’t quite go as planned or when deadlines changes. Just as long as I leave a little space to add any new tasks, it’s fine. Also, if I’m not sure how things are going to be over the next couple of days, I can plan day-by-day rather than several days at a time.

Why Not Use a PDA?

I borrowed a PDA from a friend last year and used it for a few months. I found having a single point of reference really useful. I had a note pad, diary, to do list and address book all in one place. But when I had to give the PDA back, I found it good to get back to my old system, even though it meant that I had to use a separate diary and address book. I found the Pocket PC software didn’t allow me enough flexibility as I’d hoped.

On the PDA, when tasks got completed, they got deleted. I found it useful to go back through my daily lists or my inboxes to trace when I did something or whether I actually did something at all. A couple of tasks on the PDA had mysteriously disappeared on me, leaving me wondering whether I (or the PDA) had deleted them accidentally or if I just didn’t remember ticking them off. Also, I couldn’t break down my to do list enough.

Now, with some tweaks to the to do list and a little more integration with a decent diary program, I’d find a PDA so much more useful. One place to keep notes, maintain a calendar, add new contacts, run mind mapping software… It’d also be great to be able to keep everything in one place and then just back it up occasionally, instead of keeping information in a few different places.

Related