Automation I Use To Be Fast
In the last post, I wrote about the scripts I use to make typing and coding faster. In this one I will share some more AHK scripts that I use daily.
Hotkeys
I use my numpad as a macropad. It allows me to assign specific numbers to specific apps. Windows has this function built in, but it is not as reliable as AHK. Crazy how a scripting tool can interact with Windows better than Windows itself.
OpenPBI()
{
if WinExist("ahk_exe PBIDesktop.exe") {
winactivate
}
else
Run("C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe")
}
OpenCode()
{
if WinExist("ahk_exe Code.exe") {
winactivate
}
else
Run("Code.exe")
}
<^Numpad2:: OpenPBI()
<^Numpad6:: OpenCode()
I like to organize AHK scripts according to the above structure, having functions and hotkeys separated. You could have a hotkey → script, but that is not as easy to search through.
I have 2 functions here, OpenPBI is the first. This function checks if I have a Power BI instance open, and if I do, it will activate the window. If I don’t have one open, then it will run the exe for me.
This function alone is not a working code; I need to assign it to a hotkey. In this case, it is Left Ctrl + Numpad2. The other function does the same thing with VS Code. Previously, I was a big Alt + Tab guy, but that changed with AHK. It makes it super easy to navigate between apps, and it is smooth as well. In AHK scripts ^ = Ctrl
OpenEdgeNewWindow() {
if WinExist("ahk_exe msedge.exe")
{
WinActivate
Send("^t")
}
else
{
Run("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")
Send("^t")
}
}
<^!Numpad1:: OpenEdgeNewWindow()
The above one is an extended version of the previous code. It will open Edge, but also send the keyboard keys Ctrl + t. Ctrl + t opens a new window in most browsers. So if I press Left Ctrl + Alt + Numpad1, a new browser window will open. In AHK scripts ! = Alt.
SearchSQLBI()
{
Send("+!{Right}")
Sleep(10)
Send("^c")
Sleep(100)
Run("https://dax.guide/" . A_Clipboard)
}
^!Numpad5:: SearchSQLBI()
If you code DAX a lot, the above can be super useful, since in the built-in PBI editor, there is no great documentation for the functions. The code will select the word currently under the cursor, and it will open the DAX guide with the given word in the link. I click into the function name, hit the shortcut, and boom, I have the docs right in front of me:
Another great one is the DAX Code Formatter shortcut I have:
^+f:: ; Ctrl + Shift + F
{
try {
; Copy selected text
Send("^c")
Sleep(200) ; Wait for clipboard to update
daxCode := A_Clipboard
; URL encode the DAX code
encodedDax := UriEncode(daxCode)
; Build the full URL
url := "https://www.daxformatter.com/?embed=1&l=long&s=true&fx=" . encodedDax
; Open in Browser
Run url
}
}
; Function to URL-encode text
UriEncode(str) {
static chars := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~"
out := ""
Loop Parse, str
{
ch := A_LoopField
if InStr(chars, ch)
out .= ch
else
out .= "%" . Format("{:02X}", Ord(ch))
}
return out
}
I select the DAX code, hit the shortcut, and it will open the DAX Formatter page with the code. I just need to copy-paste the result.
Extend functionality with a GUI
I usually need to transform text into uppercase, lowercase or title case. Here is a script I use to make it faster:
Edittext()
{
MyMenu := Menu()
MyMenu.add("Uppercase", Menuhandler)
MyMenu.add("Lowercase", Menuhandler)
MyMenu.add("Title", Menuhandler)
MyMenu.Show()
}
Menuhandler(Item, *) {
A_Clipboard :=""
Send "^c"
ClipWait
switch Item{
case "Uppercase":
SendText(StrUpper(A_Clipboard))
case "Lowercase":
SendText(StrLower(A_Clipboard))
case "Title":
SendText(StrTitle(A_Clipboard))
}
}
I select the text, use the shortcut, and a GUI will pop up so I can choose what type of transformation I want:
Built-in GUI for AHK is dynamite. You can extend these functionalities a lot. I hope this was a great inspiration, and you might find something useful in these. Let me know if you did so and have some other ideas for automation.



