AutoHotKey: Because everybody loves shortcuts

One application that has become vital to me is the fantastic AutoHotKey (Windows only). Using this free script-based macro/hotkey piece of software you will be able to automate every single repetitive or hard-to-reach task on your computer. Type all your macros in one single text file and AutoHotKey will make them available to your finger tips every time you start your PC. Maybe a bit too geeky for most common users, but a true gem for us pros.
I figured it would be helpful to share the shortcuts I have found most useful. Not all of these are written entirely by me, so creds go to the original authors, who hopefully accepts to be nameless in this post. For a better understanding of what AHK can do, have a look at these scripts.
# means Windows logo key, ! means Alt, ^ means Control while + means the Shif key. E.g #!b:: means Win + Alt + b.
I’m starting out basic. Here’s a shortcut to bring up the command prompt:
; Command Prompt
#c::
Run, cmd, c:\
Return
And one for quick access to the calculator:
; Run Calculator
#a::
Run, calc.exe
Return
The volume difference in my headphones compared to the internal speakers on my laptop is huge. For emergency situations, here’s a shortcut for each of the situations, unmute included.
; Volume Settings - Speaker
#s::
SoundSet,50,MASTER
SoundSet,100,WAVE
SoundSet,0,,Mute
Return
; Volume Settings - Headphones
#h::
SoundSet,50,MASTER
SoundSet,3,WAVE
SoundSet,0,,Mute
Return
Sadly, Windows doesn’t have the neat keyboard shortcut for new folder creation that all Macs have. Here’s a fix:
; New Folder
#n::
Send {AppsKey}w{Enter}
Return
When listening to iTunes, it’s great to have a quick keyboard combination for play/pause. Especially for pause. I figured out Win + z is the easiest combo:
; iTunes Play/Pause
#z::
IfWinExist, ahk_class iTunes
ControlSend, ahk_parent, {SPACE} ; play/pause toggle
Return
Sometimes it’s useful to know one’s external IP address. This script will both show it in a dialog box as well as copy it to the Clipboard.
; Copy external IP to Clipboard
#i::
MyExternalIP=0.0.0.0
TmpFile=%WinDir%\TEMP\IPAddress.TMP
URLDownloadToFile, http://www.netikus.net/show_ip.html, %TmpFile%
FileReadLine,MyExternalIP,%TmpFile%,1
FileDelete,%TmpFile%
Clipboard:=MyExternalIP
MsgBox, 0, External IP Address, Your External IP is: %MyExternalIP%.`n`nIt is now copied to the clipboard.
Return
When doing web development, you always have to test your templates in (almost) all available browsers. This shortcut brings up a dialog box where you can enter the URL (local or external) and the script will open it up in both Opera, Firefox, IE6, IE7 and Safari automatically. If you want to use this, remeber to adjust the paths to your own install locations.
; Test URL in all browsers
#b::
InputBox, url, Browser Check, Please enter URL to test:, , 400, 120
if not ErrorLevel ; User didn't press cancel
{
run, %ProgramFiles%\Internet\Opera\opera.exe "%url%"
run, %ProgramFiles%\Internet\MultipleIEs\IE6\iexplore.exe "%url%"
run, %ProgramFiles%\Internet Explorer\iexplore.exe "%url%"
run, %ProgramFiles%\Internet\Safari\Safari.exe -url "%url%"
run, %ProgramFiles%\Internet\Mozilla Firefox 2.0\firefox.exe "%url%"
}
Return
After bringing up all these windows, it’s good to have another shortcut to close them again.
; Close all browser windows
#!b::
IfWinExist, ahk_class IEFrame ; Internet Explorer 7.0
{
WinActivate ahk_class IEFrame
Send !{F4}
}
IfWinExist, ahk_class {1C03B488-D53B-4a81-97F8-754559640193} ; Safari
{
WinActivate ahk_class {1C03B488-D53B-4a81-97F8-754559640193}
Send !{F4}
}
IfWinExist, ahk_class MozillaUIWindowClass ; Firefox
{
WinActivate ahk_class MozillaUIWindowClass
Send !{F4}
}
IfWinExist, ahk_class IEFram ; Internet Explorer 6.0
{
WinActivate ahk_class IEFrame
Send !{F4}
}
IfWinExist, ahk_class OpWindow ; Opera
{
WinActivate ahk_class OpWindow
Send !{F4}
}
Return
From time to time, I’m sitting by a desk with my desktop computer (notice the irony) on the floor under the table. Instead of having to bend down to first press the CD tray button, and then to remove/insert media, I made a script that at least would spare me from the button.
; Eject/retract CD tray
#'::
Drive, Eject,,
Return
Doing HTML template development by hand includes a lot of repetitive tasks. To ease the process I have created numerous shortcuts to automatically create the most common tags. Here’s a few examples. Some of them is using the text you select for the content of the tags. An additional reward for using AutoHotKey for this is that these shortcuts will work in whichever HTML editor use.
; Create an anchor stub for selected text
#!a::
clip0 := ClipBoardAll ; Save old clipboard
SetEnv ClipBoard, ; Empty clipboard
Send ^c<a href="{#}">^v</a>
SetEnv ClipBoard, %clip0% ; Restore clipboard
Return
; Create image stub
#!i::
Send <img src="" width="" height="" alt="" />
Return
; Create div with selected text
#!d::
clip0 := ClipBoardAll ; Save old clipboard
SetEnv ClipBoard, ; Empty clipboard
Send ^c<div class="">{enter}{tab}^v{enter}{backspace}</div>
SetEnv ClipBoard, %clip0% ; Restore clipboard
Return

