Friday, January 18, 2008

My Auto-Hotkeys (and shutdown via text message!)

Update: The "Empty Recycle Bin" command I refer to below is now obsolete. A much simpler command, "FileRecycleEmpty" takes care of it all, without the extra Enter keystroke. Check my linked article for more info.

Update 2: I've since also removed the option to minimize with double-right-click. To see why, check out this article:

The following is the autohotkey file that I keep open at all times, keys.ahk. It contains hotkeys I use often, and I'll explain what these do afterwards. If you want to use this file as a template for what you do, and you have autohotkey installed, just copy and paste the entire thing into a text file with the extension .ahk:

#SingleInstance force
DetectHiddenText, On
SetTitleMatchMode 2
SetTitleMatchMode, Slow

WinWait, ahk_class #32770, *******: standby
WinActivate
WinClose
Run C:\Documents and Settings\Arvin\My Documents\scripts\hibernate.ahk
Reload

!o:: Run C:\Documents and Settings\Arvin\My Documents\scripts\open.ahk
!c:: Run C:\Documents and Settings\Arvin\My Documents\scripts\close.ahk
!h:: Run C:\Documents and Settings\Arvin\My Documents\scripts\hibernate.ahk
!s:: Run C:\Documents and Settings\Arvin\My Documents\scripts\
!q:: Run F:\Video Projects\
!e:: Edit
^!r:: Shutdown, 6
!x::
Run C:\Documents and Settings\Arvin\My Documents\scripts\EmptyRecycleBin.exe
Sleep, 500
Send, {Enter}

~RButton::
If (A_PriorHotkey != A_ThisHotkey OR A_TimeSincePriorHotkey > 500)
Return
Sleep 200 ; time for context to appear
Send {Esc} ; close context menu
WinMinimize, A ; minimize active window
Return

#m:: ; Win+O hotkey that turns off the monitor.
Sleep 1000 ; Give user a chance to release keys (in case their release would wake up the monitor again).
; Turn Monitor Off:
SendMessage, 0x112, 0xF170, 2,, Program Manager ; 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
; Note for the above: Use -1 in place of 2 to turn the monitor on.
; Use 1 in place of 2 to activate the monitor's low-power mode.
return

Let's go through what each part means:
#SingleInstance force
DetectHiddenText, On
SetTitleMatchMode 2
SetTitleMatchMode, Slow
The first line makes sure only one instance of the script is running at a time. The 2nd to 4th lines allow the script to monitor the text contained within the open windows. This is important for the next sectoin of scripts:
WinWait, ahk_class #32770, *******: standby
WinActivate
WinClose
Run C:\Documents and Settings\Arvin\My Documents\scripts\hibernate.ahk
Reload
This section waits for the existence of a window that's got the ahk_class of 32770 (you can see what the class of a window is using the AutoHotkey Window Spy), and contains the text "******: standby" (edited for security).

Basically, this waits for a Miranda IM window from my mobile phone (I send the im using text message) that says: standby. Autohotkey then closes the IM window, then runs my hibernate computer routine (I'll show you that soon as well!), and then reloads the keys.ahk script. Again, I plan on elaborating on this process in a future article.
!c:: Run C:\Documents and Settings\Arvin\My Documents\scripts\close.ahk
!o:: Run C:\Documents and Settings\Arvin\My Documents\scripts\open.ahk
!h:: Run C:\Documents and Settings\Arvin\My Documents\scripts\hibernate.ahk
!s:: Run C:\Documents and Settings\Arvin\My Documents\scripts\
!q:: Run F:\Video Projects\
!e:: Edit
^!r:: Shutdown, 6
These are the various hotkeys that make navigating my computer a snap. The symbol (!) implies holding down the ALT key, so "!c" means hitting ALT-C runs my "Close programs" routine (close.ahk) . I use this to shut down programs in the background that I want to shut down if I really want to free my system resources up, like for playing a game or video rendering. Open.ahk reopens those programs when I'm done.

The commands that run a directory open that directory when the keys are pressed. !e:: runs the "Edit this script" command. And finally, "^!r" (Shift-Alt-r) force restarts my computer.
!x::
Run C:\Documents and Settings\Arvin\My Documents\scripts\EmptyRecycleBin.exe
Sleep, 500
Send, {Enter}
Hitting Shift-X runs emptyrecyclebin.exe, a free utility that empties the recycle bin. The next 2 lines waits 500 milliseconds, and then the computer sends and "Enter" keypress. This is because while the emptyrecyclebin program empties the recycle bin, if you still have the Recycle Bin set to ask you if you want to permanently delete the files within, you still have to press OK (or hit ENTER, as OK is already highlighted).
~RButton::
If (A_PriorHotkey != A_ThisHotkey OR A_TimeSincePriorHotkey > 500)
Return
Sleep 200 ; time for context to appear
Send {Esc} ; close context menu
WinMinimize, A ; minimize active window
Return
I got this script from Lifehacker, I believe. It lets me double-right click to minimize the current active window. Neat, though I still need to remember to use it more often.

#m:: ; Win+O hotkey that turns off the monitor.
Sleep 1000 ; Give user a chance to release keys (in case their release would wake up the monitor again).
; Turn Monitor Off:
SendMessage, 0x112, 0xF170, 2,, Program Manager ; 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
; Note for the above: Use -1 in place of 2 to turn the monitor on.
; Use 1 in place of 2 to activate the monitor's low-power mode.
return
Finally, that part sends the monitor into standby mode by pressing Windows-M. I believe I got this script from the Autohotkey forums.

And that's it! Hope that inspires you to write your own super-simple script that automates much of your repetitive tasks!

Related Posts by Categories



Widget by Hoctro | Jack Book

6 comments:

Anonymous said...

Thanks so much for posting that. It's going to come in very handy. How are you sending text messages to your IM client?

Arvin Bautista said...

Good question. I'll write an article in the next few days regarding how I go about doing that, but in the meantime, search for stuff like "send text messages over aim" or somesuch (i don't know if there's an available feature for MSN, Yahoo, and Skype, unfortunately).

Anonymous said...

I found it! It's a pretty good walk and I got things working. It covers most cell phone providers, too.

Anonymous said...

You might want to include this link for people who need some direction on how to send a text message to an AIM account (like me...)

http://mymobile.aol.com/portal/im/userguides.html

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Kashif said...

This works perfectly for me!

Thank you for your good work