Google docs bookmaklet to format code

Something has been annoying me for some time as I write this book in Google Docs: I want to be able to format text as code (Courier New) only using the keyboard. So I came up with this bookmarklet. It's one of those "works for me" so if it doesn't work for you feel free to modify and post here your version.

Code

Basically I attach an event (FF way, so won't work in IE) that listens to the keyboard combination ALT+x and then calls the appropriate editor command:

javascript:(
function(){
  window.frames[1].document.addEventListener(
    'keypress',
    function(e){
      if (e.altKey && e.charCode === 120){
        EditorCommand('fontname', 'Courier New'); 
        return false;
      }
    },
    false);
}
)()

Download

Right-click, bookmark:

Alt+X

This entry was posted on Sunday, January 27th, 2008 and is filed under bookmarklets, writing. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

2 Responses to “Google docs bookmaklet to format code”

  1. phpied.com » Blog Archive » replace selected text (Firefox) Says:

    [...] Luckily I’m so close (and yet so far) to finishing this book, otherwise I won’t be able to help myself but create a whole toolbar of bookmarklets for “power” Google doc users… Post this entry to: » del.icio.us  » Digg  » Furl  » Newsvine  » reddit  » Y! [...]

  2. numerous ecig skin Says:

    Hello there, I found your site via Google while searching for a related subject, your site got here up, it seems great. I’ve bookmarked to my favourites|added to my bookmarks.

Leave a Reply