Calendar

July 2008
S M T W T F S
« Jun   Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Most Recent Posts

Search Blog:

Autohotkeys

July 12th, 2008 by Chuck Sharp

So, I reviewed Activewords awhile back. It’s very cool, easy, and powerful. Since Autohotkeys is free, however, and it does at least the vast majority of things that AW can, and many things AW can’t, I thought I’d give it a thorough go a couple of months ago.

Autohotkeys is a scripting language plus hotkey program. You can write little programs (scripts) that, when run, do their jobs and exit. However, you can edit a little script file called autohotkeys.ahk that, when run, loads and sits in your toolbar. From there, it watched all of your keystrokes. You can tell it what to do when certain keystrokes are hit.

This is powerful enough: it’s fairly easy set up all your most common programs, files, and websites to come up with a quick hotkey (windows key + W, or control+alt+E, etc). My problem is that I rarely remember these shortcuts.

My Autohotkeys.ahk file:

Here’s my autohotkeys.ahk (comment lines start with ‘;’):

; ‘#0′ means windows key + the 0 key. That key starts my file manager, Xplorer2 Lite.

#0::Run C:\Program Files\zabkat\xplorer2_lite\xplorer2_lite.exe %A_MyDocuments%\Files %A_MyDocuments%\In
; ‘#1′ = Windows key + 1. This loads my ‘chuck’s head’ mind map file (MindManager software)
#1::Run %A_MyDocuments%\files\Personal Management\me.mmap

; Loads gmail website in default browser (firefox of course)

#2::Run https://mail.google.com
; Windows+C starts up the calculater. Very useful.
#c::Run %SystemRoot%\system32\calc.exe
; Windows+g takes whatever’s highlited on the screen and google’s it.
#g::
Send ^c
Run http://www.google.com/search?q=%Clipboard%
Return
; Bring Outlook to the front if it’s loaded, otherwise start it.
#o::
IfWinExist ahk_class rctrl_renwnd32
WinActivate
else
Run c:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE
return
; Create a new task in outlook.
#k::
IfWinExist ahk_class rctrl_renwnd32
WinActivate
sleep 200
Send ^+k
return

; Windows+N will start Notepad++, a free notepad replacement, very convenient for a quick note

#n::
IfWinExist Notepad++
WinActivate
else
Run “C:\Program Files\Notepad++\notepad++.exe”
return

; The next 3 lines are interesting. These start new scripts that all work the same way. Explained below.

#w::Run %A_MyDocuments%\bin\webdial.ahk

#z::Run %A_MyDocuments%\bin\autowords.ahk

#b::Run %A_MyDocuments%\bin\bookmarks.ahk
; Edit this file.
#/::Edit
; Create a timestamped text entry in F:\timelog.txt
#i::
InputBox, logvar, Logger, Log entry?
FormatTime, TimeString,, MM-dd-yyyy hh:mm
FileAppend, %TimeString% %logvar%`n, F:\timelog.txt
return
; These are common misspellings and abbreviations, which AHK will automatically translate.

; Whenever ‘wsig’ is typed, my work signature will be typed out by AHK in any program

::wsig::Chuck Sharp, RHCE{enter}Server Team, XXXXXXXX{enter}(XXX) XXX-XXXX

;Common misspellings that will be auto-corrected anywhere I type them.
:C:DOne::Done
:C:CHuck::Chuck
:C:CHarles::Charles
:C:SHarp::Sharp

My Autowords answer to Activewords

Those AHK scripts referenced (rdp.ahk, autowords.ahk, etc) all work on the same logic: ask for a word, look for that word in a text file, and run the command that the text file tells it to. This is the real magic in my AHK implementation. It gives me the basic Activewords functionality I want, for free. Let me show you what a portion of my autowords.txt file looks like:

delicious,http://del.icio.us/chucksharp
dns,dnslookup.ahk
facebook,http://facebook.com
ilo,ilo.ahk
jott,http://jott.com
logmein,http://logmein.com
mountshares,mountshares.au3
rdp,rdp.ahk
reader,http://google.com/reader
ssh,putty.exe -load “work rhel”

When I press the combo Windows key + Z, I get this box:

Autowords
When I type in, say, “reader” and press enter, AHK will load Google Reader in firefox. Quick and easy. Here’s the code to Autowords:

InDir =  %A_MyDocuments%bin
InputMsg = "Enter word or  for list:"

StringSplit MyNameTmp, A_ScriptName, `.
MyName = %MyNameTmp1%
infile = %InDir%%MyName%.txt

InputBox, OutputVar, %MyName%, %InputMsg%
If ErrorLevel
ExitApp
Else
{
If OutputVar =
{
; Create the ListView with two columns, Name and Size:
Gui, Add, ListView, r20 w700 gMyListView, Name|Run
Gui, Add, Button, Default, OK

; Gather a list of file names from a folder and put them into the ListView:
;Loop, %A_MyDocuments%*.*
;    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)
Loop, read, %infile%
{
StringSplit, ItemArray, A_LoopReadLine,`,,%A_Space%%A_Tab%
LV_Add("", ItemArray1, ItemArray2)
}
LV_ModifyCol()  ; Auto-size each column to fit its contents.

; Display the window and return. The script will be notified whenever the user double clicks a row.
Gui, Show
return
}

Loop, read, %infile%
{
StringSplit, ItemArray, A_LoopReadLine,`,,%A_Space%%A_Tab%
If ItemArray1 = %OutputVar%
{
Run, %ItemArray2%,, UseErrorLevel
If ErrorLevel = ERROR
MsgBox Could not launch %ItemArray2%
ExitApp
}
}
MsgBox "%OutputVar%" not found
ExitApp
}

MyListView:
if A_GuiEvent <> DoubleClick
return
; Otherwise, the user double-clicked a list item, so treat that the same as pressing OK.
; So fall through to the next label.
ButtonOK:
RowNum := LV_GetNext()
;MsgBox %RowNum%
LV_GetText(RowText, RowNum, 2)  ; Get the text from the row's second field.
;MsgBox %RowText%
Run, %RowText%,, UseErrorLevel
if ErrorLevel = ERROR
MsgBox Could not launch the specified file.  Perhaps it is not associated with anything.
ExitApp
return
Esc::ExitApp
GuiClose:  ; Indicate that the script should exit automatically when the window is closed.
ExitApp

How to use this script

  1. Install Autohotkey
  2. Download the script or cut and paste it into a file.
  3. Name the script whatever you want (with an .ahk extension), and put it into a directory called “bin” in your Documents folder.
  4. Whatever filenameyou chose, create a file called filename.txt, where filename should be replaced by whatever name you picked.
  5. Put entries in this text file like the examples I listed above.
  6. Run the script to test it, type in one of your words, and see what happens. If you want to see a list of words, hit enter.
  7. Put a shortcut in your autohotkey.ahk file like this: #z::Run %A_MyDocuments%\bin\autowords.ahk
  8. Run your autohotkey file (or reload it). When it’s running, you’ll see a green ‘H’ in the icon notification area in the lower corner of your screen.
  9. Press Windows key + Z to pull up the autowords text box.
Share this post:
  • Digg
  • del.icio.us
  • BlogMemes
  • Furl
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Entry Filed under: Productivity, Review

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed