EMZETT.
Login

Automating keyboard and tasks: AutoHotkey, batch and PowerShell

In short: Small scripts take routine off your hands: AutoHotkey for hotkeys and text, batch files for simple sequences, PowerShell for files, system administration and data.

In more detail: If you do a task by hand three times, you should automate it. Windows offers graded tools; the way of thinking is the same as with shell scripts, Python and Make.

In Depth

AutoHotkey (AHK)

Scripting language for hotkeys, text snippets and window control:

#Requires AutoHotkey v2.0
:*:mfg::Kind regards`nMichael   ; text snippet
^!n::Run "notepad.exe"                      ; Ctrl+Alt+N
#HotIf WinActive("ahk_exe chrome.exe")
^+t::Send "^+t"
#HotIf

Good for gaming comfort (but not in online games with anti-cheat: macros may count as cheating and lead to a ban), accessibility, recurring inputs. Run scripts only from trustworthy sources. Alternatives: PowerToys (Keyboard Manager, FancyZones, Run), Espanso (text snippets), xdotool/sxhkd (Linux).

Batch files (.bat/.cmd)

Simplest automation via cmd:

@echo off
set SOURCE=C:\Projects
set TARGET=D:\Backup\%DATE:~-4%-%DATE:~3,2%-%DATE:~0,2%
robocopy "%SOURCE%" "%TARGET%" /MIR /R:1 /W:1
if errorlevel 8 echo ERROR while copying
pause

robocopy is the robust copy tool. Batch is outdated and awkward (quoting, string handling), but suffices for small things. Start time-controlled with the Task Scheduler.

PowerShell

Object-oriented shell (cmdlets Verb-Noun):

Get-ChildItem C:\Photos -Recurse -Include *.jpg |
  Where-Object Length -gt 5MB |
  Sort-Object Length -Descending |
  Select-Object -First 10 FullName,@{n='MB';e={[math]::Round($_.Length/1MB,1)}}
 
Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace '^old_','new_' }
Invoke-RestMethod https://api.example.org/data | ConvertTo-Json

For mass renaming, cleaning up, system queries, Active Directory, CSV/JSON, REST APIs. First simulate with -WhatIf, explore with Get-Help and Get-Member. Scripts in .ps1, mind the execution policy.

Which tool when?

  • Hotkey/text: AutoHotkey, PowerToys.
  • Copying/backing up files: robocopy, rsync (Linux).
  • More complex logic/data: PowerShell or Python.
  • Browser sequences: Playwright/Selenium (mind legal situation and terms).
  • Across applications without code: Power Automate, Zapier/n8n.
  • Rules: solve manually first, then automate; test with copies; write logs; no passwords in the script; version scripts (Git) and comment them. At work use automation only within company rules.

See also: PowerShell, Windows Task Scheduler, Writing shell scripts