Well, what do you know? It turns out I do have a blog. It may be the 14th instance of this space, which has known the horrors of my first DIY PHP projects. I’ve decided to let WordPress handle all the drama this time, but rest assured I’ll definitely be probing inside its brains later on. Anyways, welcome to the show. I’ll try to be as less annoying as possible in these columns, but if you’re wondering, I’ll be talking a lot about geek related stuff. Think PHP, MySQL, CSS, Javascript, and Tools that help me bend the matrix to my will. You’re still here? Good.
Ever since I’ve been coding, I’ve had the problem of setting up a good workspace. I’ve lately switched from Programmer’s Notepad to Sublime Text 2 (I’ll write a review of this amazing software later), and my next step will probably be to rearrange my desk and go multi-monitor. The problem right now is that I don’t have the income -yet- to offer myself a battlestation worthy of Kevin Connoly‘s six monitors dream office. So I’m still struggling with my good old BenQ G2400W 24″ LCD monitor, and I Alt-Tab. A lot.
Because it’s pretty obvious. You’re editing a CSS, and it has to be cross-browser compliant. And it never is. Most of the time, it’s because of the absolutely evil abomination tricky rendering bugger that is Internet Explorer. Other times it’s because you can’t code proper code the first time. But let’s face it, it’s mostly IE’s fault. So you constantly Alt-Tab between your Editor/IDE and Chrome/Firefox/IE (and Safari and Opera if you’re really into versatility). At the end of the day, you’ve spent countless minutes looking at your browser windows (often confusing them), Alt-Tabbing between them, while every nano-second of your time is precious. How wonderful would it be if they could, oh I don’t know, refresh themselves automatically? Well, one might suggest putting an auto-refresh syntax in the body of the document. It’s completely dirty. And there’s always LiveReload, but it is still in early stage of development, and not yet available for Windows even as a Beta.
Enters AutoHotKey.
AutoHotKey is an amazing software, exactly the kind of tools I love. It’s super light, works instantly, is configurable at will, and has an outstanding potential. In a nutshell, it allows you to set up automatic keystrokes based on what you’ve typed. It can do really simple tasks, like automatically replace “btw” with “by the way” in an email, or combine keystrokes with mouse gestures to let you control your computer sound volume. Or it could automatically refresh your browser windows every time you hit Ctrl + S on your Editor of choice !
I’ve put together a simple script which lets you do that. It basically listens to incoming keystrokes, and if you’re inside your text editor (Sublime Text in my case), refreshes any active instance of Chrome, Firefox, and IE, and gives your focus back on the editor. It happens almost instantly, and saves you those precious minutes previously lost.
Here is the code :
$^s::
SetTitleMatchMode, 2
IfWinActive, Sublime Text 2
{
Send ^s
IfWinExist, Mozilla Firefox
{
WinActivate
Send ^r
}
IfWinExist, Google Chrome
{
WinActivate
Send ^r
}
IfWinExist, Internet Explorer
{
WinActivate
Send ^r
}
WinActivate, Sublime Text 2
}
else
{
Send ^s
}
return
(You can find it on Pastebin too, with comments on what does what).
Basically, it scans the opened windows, and when it finds a web browser, sends a refresh command, then focuses back on Sublime Text. It also sends a Ctrl + S command to ST to actually save the file. You can edit this script as you like. For instance, replace “Sublime Text 2″ with “Notepad++” if you’re a N++ user.
Don’t hesitate to let me know how you’ve improved this script in the comments!