New AHK File: Templated AutoHotkey v2 Scripts in VS Code or Cursor

How many times a day do you start a new AutoHotkey script?

For me it’s a lot. And every time it was the same routine: new file, pick a folder, type a name, paste in my usual header lines.

New AHK File does that whole routine for you. Type a name, hit Enter, and the new script opens in VS Code or Cursor with your template already in it. 😊

New AHK File: start a new AutoHotkey v2 script in VS Code or Cursor

Type a Name, Get a Script That Opens in Your Editor


Run it and a small window asks for a file name. You can type it with or without the .ahk on the end.

Click OK and it saves the new file, then opens it in your editor:

  • Started from Cursor? The file opens in Cursor
  • Anywhere else? It opens in VS Code
  • Only have one of them? It uses the one you have

Leave the name empty and you get a file called “Temp Script”. Press Escape to back out.

Your Template, Editable Right in the Window


Under the name box is the template that goes into every new file. It starts with the lines I put at the top of most of my scripts:

  • #Requires AutoHotkey v2 and #SingleInstance Force
  • DetectHiddenWindows turned on
  • A tray icon line and an Open Folder item in the tray menu

Need something different just this once? Edit the template in the window before you click OK.

Want to change it for good? It’s a plain text block near the top of the script.

It Never Overwrites a File


If the name is already taken, New AHK File picks the next free one. “Test” becomes “Test2”, then “Test3”.

If the name already ends in a number, it counts up from there. So you never lose a script by accident.

Put it on Ctrl+N: the top of the script has a 3-line hotkey block you paste into a script you always have running. Ctrl+N then starts New AHK File, but only while VS Code, Cursor or File Explorer is the active window.

What’s in the Download


  • NewAHKFile.ahk: one AutoHotkey v2 script, no libraries needed

Set three things at the top: the folder where new scripts go, the window font size, and your template.

If that folder doesn’t exist on your PC, new files are saved next to the script instead.

Requirements: Windows, AutoHotkey v2, and VS Code or Cursor installed in the usual per-user location.

Get New AHK File


New AHK File is free. Grab it and make the template yours.

It’s a small thing, but small things you do 20 times a day add up. ⚡

Joe

Comments are closed.