24

I use AutoHotKey for Windows macros. Most commonly I use it to define hotkeys that start/focus particular apps, and one to send an instant email message into my ToDo list. I also have an emergency one that kills all of my big memory-hogging apps (Outlook, Firefox, etc).

So, does anyone have any good AHK macros to share?

leeborkman
  • 241
  • 1
  • 5
  • 9

9 Answers9

15

Very simple and useful snippet:

SetTitleMatchMode RegEx ;
; Stuff to do when Windows Explorer is open
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass
    ; create new folder
    ;
    ^!n::Send !fwf

    ; create new text file
    ;
    ^!t::Send !fwt

    ; open 'cmd' in the current directory
    ;
    ^!c::
        OpenCmdInCurrent()
    return
#IfWinActive

; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenCmdInCurrent()
{
    WinGetText, full_path, A  ; This is required to get the full path of the file from the address bar

    ; Split on newline (`n)
    StringSplit, word_array, full_path, `n
    full_path = %word_array1%   ; Take the first element from the array

    ; Just in case - remove all carriage returns (`r)
    StringReplace, full_path, full_path, `r, , all  
    full_path := RegExReplace(full_path, "^Address: ", "") ;

    IfInString full_path, \
    {
        Run, cmd /K cd /D "%full_path%"
    }
    else
    {
        Run, cmd /K cd /D "C:\ "
    }
}
pmr
  • 58,701
  • 10
  • 113
  • 156
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • 1
    I had to add two lines to get this script working in Win7 with AHK 1.048.05: [1] SetTitleMatchMode RegEx ; at top of script in autorun section [2] full_path := RegExReplace(full_path, "^Address: ", "") ; strip to bare address – Leftium Apr 30 '10 at 23:44
  • 1
    I'm a newb in autohotkey scripting and am having trouble implementing Leftium's fixes, which lines do the new commands go to? – raveren Feb 11 '11 at 10:02
  • This didn't work on my platform when I hit ^!n and other command list above ...I don't know what happened – harris Nov 05 '13 at 03:12
12

Here is so simple but useful script:

^SPACE::  Winset, Alwaysontop, , A

Use CTRL + Space to set any window always on top.

EvanBlack
  • 759
  • 8
  • 25
10

Add surrounding quotes on selected text/word
Useful when writing emails or during coding...

Doubleclick word, hit Win+X, have quotes around

; Win + X
#x:: ; Attention:  Strips formatting from the clipboard too!
Send ^c
clipboard = "%clipboard%"
; Remove space introduced by WORD
StringReplace, clipboard, clipboard,%A_SPACE%",", All
Send ^v
return
Peter Gfader
  • 7,673
  • 8
  • 55
  • 56
  • 1
    vscode does this by default. just select the word and press quotes. – tinker Sep 19 '20 at 04:09
  • [Here](https://www.autohotkey.com/boards/viewtopic.php?t=25298) is an extended version of your code snipped, which works also with all symbols (and characters), e.g. parenthesis, square brackets, single quotes... It's very pratical. – mouwsy Jan 31 '21 at 17:47
8

; I have this in my start menu so that I won't ruin my ears when I put on my headphones after rebooting my computer

sleep, 5000
SoundSet, 1.5 ; really low volume
Bård
  • 634
  • 6
  • 20
5

I create new Outlook objects with AutoHotKey

; Win+Shift+M = new email

#+m::  Run "mailto:"

; Outlook

#^M::  Run "%ProgramFiles%\Microsoft Office\Office12\OUTLOOK.EXE" /recycle

; Win+Shift+A = create new calendar appointment

#+A::  Run "%ProgramFiles%\Microsoft Office\Office12\OUTLOOK.EXE"/c ipm.appointment

; Win+Shift+T = create new Task ; Win+Shift+K = New task

#+T::  Run "%ProgramFiles%\Microsoft Office\Office12\OUTLOOK.EXE"/c ipm.task
#+K::  Run "%ProgramFiles%\Microsoft Office\Office12\OUTLOOK.EXE"/c ipm.task
Peter Gfader
  • 7,673
  • 8
  • 55
  • 56
5

Here's a dead-simple snippet to quickly close the current window using a mouse button.

It's one of the actions you perform most often in Windows, and you'll be surprised at how much time you save by no longer having to shoot for that little X. With a 5-button mouse, I find this a very useful reassignment of the "Forward" button.

#IfWinActive  ;Close active window when mouse button 5 is pressed
  XButton2::
    SendInput {Alt Down}{F4}{Alt Up}
    Return
#IfWinActive  

To take into account programs that use tabbed documents (like web browsers), here's a more comprehensive version:

;-----------------------------------------------------------------------------
; Bind Mouse Button 5 to Close Tab / Close Window command
;-----------------------------------------------------------------------------

; Create a group to hold windows which will use Ctrl+F4 instead of Alt+F4
GroupAdd, CtrlCloseGroup, ahk_class IEFrame             ; Internet Explorer
GroupAdd, CtrlCloseGroup, ahk_class Chrome_WidgetWin_0  ; Google Chrome
; (Add more programs that use tabbed documents here)
Return

; For windows in above group, bind mouse button to Ctrl+F4
#IfWinActive, ahk_group CtrlCloseGroup
  XButton2::
    SendInput {Ctrl Down}{F4}{Ctrl Up}
    Return
#IfWinActive  

; For everything else, bind mouse button to Alt+F4
#IfWinActive
  XButton2::
    SendInput {Alt Down}{F4}{Alt Up}
    Return
#IfWinActive  

; In FireFox, bind to Ctrl+W instead, so that the close command also works
; on the Downloads window.
#IfWinActive, ahk_class MozillaUIWindowClass
  XButton2::
    SendInput {Ctrl Down}w{Ctrl Up}
    Return
#IfWinActive

Visual Studio 2010 can't easily be added to the CtrlCloseGroup above, as it's window class / title aren't easily predictable (I think). Here's the snippet I use to handle it, including a couple additional helpful bindings:

SetTitleMatchMode, 2  ; Move this line to the top of your script

;-----------------------------------------------------------------------------
; Visual Studio 2010
;-----------------------------------------------------------------------------

#IfWinActive, Microsoft Visual Studio

  ; Make the middle mouse button jump to the definition of any token
  MButton::
    Click Left  ; put the cursor where you clicked
    Send {Shift Down}{F2}{Shift Up}
    Return

  ; Make the Back button on the mouse jump you back to the previous area
  ; of code you were working on.
  XButton1::
    Send {Ctrl Down}{Shift Down}{F2}{Shift Up}{Ctrl Up}
    Return

  ; Bind the Forward button to close the current tab
  XButton2::
    SendInput {Ctrl Down}{F4}{Ctrl Up}
    Return

#IfWinActive

I also find it useful in Outlook to map ALT+1, ALT+2, etc. to macros I wrote which move the currently selected message(s) to specific folders (eg. "Personal Filed", "Work Filed", etc) but that's a bit more complicated.

rkagerer
  • 4,157
  • 1
  • 26
  • 29
  • This is my favorite AHK script, it's a very convenient time saver. I'm glad you wrote this, thank you very much. – mouwsy Jan 31 '21 at 17:40
4

There are tons of good ones in the AutoHotKey Forum:

http://www.autohotkey.com/forum/forum-2.html&sid=8149586e9d533532ea76e71e8c9e5b7b

How good? really depends on what you want/need.

scunliffe
  • 62,582
  • 25
  • 126
  • 161
3

I use this one all the time, usually for quick access to the MySQL command line.

http://lifehacker.com/software/featured-windows-download/make-a-quake+style-command-prompt-with-autohotkey-297607.php

Feet
  • 2,567
  • 3
  • 22
  • 29
2

Fix an issue when copying file to FTP server when the "Copying" dialog appears on top of the "Confirm File Replace" dialog (very annoying):

SetTimer, FocusOnWindow, 500
return

FocusOnWindow:
IfWinExist, Confirm File Replace
    WinActivate
return

One to deactivate the useless Caps-lock key:

Capslock::
return

CTRL + shift + c will copy colour below cursor to the clipboard (in hexadecimal)

^+c::
MouseGetPos,x,y
PixelGetColor,rgb,x,y,RGB
StringTrimLeft,rgb,rgb,2
Clipboard=%rgb%
Return

Write your email address in the active field (Win key + m)

#m::
Send, my@email.com{LWINUP}
Sleep, 100
Send, {TAB}
return
Johann
  • 12,158
  • 11
  • 62
  • 89