Automation using AHK

Disclaimer: Most of the scripts I am presenting in this post is a collection that I made searching the web.

AutoHotkey (AHK) is a scripting language that allow us to automate our daily tasks, create macros and much more.

The benefits of automation in a computing world is such a big deal, and not so many people take advantage from it, as they don't know what they could use it for.

In reality it's really simple, every time you find yourself repeating the same exact task over and over again you have a perfect indication that you should probably automate that process. Of course writing the script to automate your task will take time and testing, but in the long run it will win over doing the same actions manually.

I want to make it clear that automation is not only useful for programmers but for anyone that use a computer.

To give you an idea let's say that each and every morning I am:

  • Checking mails on the web client
  • Opening my preferred online newspaper
  • Open Microsof Excel
  • Open your favorite messaging desktop client
  • Open a note application
  • Open youtube/spotify and start listening music
  • Open Microsoft team

You could achieve this 7 actions with just one single click.

Of course this script won't give you such a massive benefit, but you get the idea why automation is a powerful tool.

Automation will save you a lot of time and money.

The sentence I use the most when dealing with automation is "Working smarter instead of harder".

AHK does require some base scripting knowledge but in my opinion it's well worth put some time into it and learn such a useful skill.

I use AHK in conjunction with Stream Deck, so I don't have to remember complex key bindings like CTRL+ALT+WIN+P

AHK scripts run with keyboard key-bindings, so you can personalize them as you wish.

Auto login (use webdriver and python3)

I wrote this script myself as I needed a way to autologin a website.

How to use: SHIFT+F2

Requirements: Python v.3.x.x


Send c:{enter} ; Go to C drive
Send cd C:\gitea\auto-login{enter} ; Go to scripts folder
Send python{enter} ; Execute python script

from selenium import webdriver
from import Service
from import Options
from import By

options = Options()

options.binary_location=r'C:/Program Files/Google/Chrome/Application/chrome.exe'

options.add_experimental_option('excludeSwitches', ['enable-logging'])

s = Service('./chromedriver_win32/chromedriver.exe')

browser = webdriver.Chrome(service=s, options=options)


username = "name"

password = "pass"





print("\nLogged-in succesfully...");

Open Windows terminal

How to use: CTRL+SHIFT+C

    windowHandleId := WinExist("ahk_exe WindowsTerminal.exe")
    windowExistsAlready := windowHandleId > 0

    ; If the Windows Terminal is already open, determine if we should put it in focus or minimize it.
    if (windowExistsAlready = true)
        activeWindowHandleId := WinExist("A")
        windowIsAlreadyActive := activeWindowHandleId == windowHandleId

    if (windowIsAlreadyActive)
        ; Minimize the window.
        WinMinimize, "ahk_id %windowHandleId%"
        ; Put the window in focus.
        WinActivate, "ahk_id %windowHandleId%"
        WinShow, "ahk_id %windowHandleId%"
    ; Else its not already open, so launch it.
        Run, wt

; Hotkey to use Ctrl+Shift+C to launch/restore the Windows Terminal.

Prompt in current folder

How to use: CTRL+ALT+U

^!u::     ; Use ctrl+alt+u to open cmd in current selected folder
  Send, !d
  Send, ^c
  Sleep 50
  Run wt, %clipboard%

Search current selected text

How to use: CTRL+ALT+C

^!c:: ; use ctrl+alt+c to search on google
 Send, ^c
 Sleep 50

Side by side folder

How to use: CTRL+SHIFT+WIN+E

^+#e::                                  ; use ctrl+shift+win+e
{                                       ; to open new explorer window with the same selected folder
  Send, #{Left}
  Sleep 50
  Send, !d
  Sleep 50
  Send, ^c
  Sleep 100
  Run, Explorer "%clipboard%"
  Sleep 900
  Send, !{Up}
  Sleep 600
  Send, #{Right}

Open Websites and Apps

^#1::Run ""   ; use ctrl+win+1 to open gitlab
^#2::Run ""   ; use ctrl+win+2 to open youtrack
^#3::Run "" ; use ctrl+win+3 to open Jenkins
^#4::Run "" ; use ctrl+win+4 to open CssTricks

;^+!1::Run ""   ; use ctrl+shift+alt+1
;^+!2::Run ""   ; use ctrl+shift+alt+2
;^+!3::Run ""   ; use ctrl+shift+alt+3
;^+!4::Run ""   ; use ctrl+shift+alt+4
;^+!5::Run ""   ; use ctrl+shift+alt+5
;^+!6::Run ""

;^!t::Run cmd, C:\Users\Username         ; use ctrl+alt+t to run Cmd
;^!w::Run firefox.exe                     ; use ctrl+alt+w to run Firefox
;^!s::Run C:\Program Files\Sublime Text 3\sublime_text.exe
^!v::Run C:\Users\username\AppData\Local\Programs\Microsoft VS Code\Code.exe ;use ctrl+alt+v to run vscode

Fetch and pull

How to use: CTRL+ALT+P

  SetWorkingDir, C:\repos\myrepo
  Run %comspec%  "%A_WorkingDir%"
  Sleep, 500
  Send, git fetch
  Send, {Enter}
  Send, git pull
  Send, {Enter}
  Sleep, 500
  Send, Exit,
  Send, {Enter}

Copy color (HEX) to clipboard


; Copy to clipboard the HEX color of the pixel under your cursor using CTRL+Win+LeftClick
  MouseGetPos, MouseX, MouseY
  PixelGetColor, color, %MouseX%, %MouseY%, RGB
  StringLower, color, color
  clipboard := SubStr(color, 3)
Show Comments