3 minute read

The Windows context menu provides an Edit Script option for AutoHotkey .ahk files. Unfortunately, it defaults to opening in Notepad, which is not a great editor for AutoHotkey scripts.

Windows File Explorer context menu for .ahk files Edit Script option

The same is true when using the Edit This Script option from the context menu of the tray icon for a running script.

A running AutoHotkey scripts tray icon context menu

Fortunately there is a simple way to change the default editor for AutoHotkey scripts.

Set the default editor for AutoHotkey scripts in the Registry

I came across this forum post and this one, which led me to the solution of simply modifying the following registry key:

HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command

Further below, I provide some download files to easily modify this registry key for some popular editors. You can use those, but let’s first look at how to manually modify the registry key.

Manually update the registry value

To manually modify the registry key value:

  1. Press Windows Key+R to access the Run dialog.
  2. Type regedit and hit OK to open the Registry Editor.
  3. Navigate to HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command.
  4. Double-click the (Default) value to edit it, and update the exe path.

By default, it will have a value like notepad.exe "%1".

You will want to replace the path to the Notepad executable with the path to your preferred editor’s executable, and surround the file path with double quotes.

I use Visual Studio Code, so this is what my registry entry looks like after updating it:

Setting the registry entry for Visual Studio Code

Creating the registry key if it does not exist

If the registry key does not exist, we can create it manually by doing the following in the Registry Editor:

  1. Navigate to HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell in the Registry Editor.
  2. Right-click the Shell folder, select New > Key and name this Edit.
  3. Double-click the (Default) entry in the new Edit folder, and set its value to Edit Script.
  4. Right-click the Edit folder, select New > Key and name this Command.
  5. The (Default) entry should now exist in the new Command folder, and you should be able to set its value as described above.

There are many editors that can be used to edit AutoHotkey scripts, some more popular than others. Most have extensions/plugins that should be installed for the best experience. Below are some popular editors and their registry value to use.

I also included a .reg file that you can download and run to set the registry entry for you, so that you don’t need to make manual edits in the Registry Editor as shown above.


Notepad++:

"C:\Program Files\Notepad++\notepad++.exe" "%1"

Download Notepad++ .reg file


Visual Studio Code:

"C:\Users\[YOUR USERNAME GOES HERE]\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%1"

NOTE: You need to replace [YOUR USERNAME GOES HERE] with your actual username.

No .reg file to download is provided since the username in the executable file path will be unique to you.


SciTE4AutoHotkey:

"C:\Program Files\AutoHotkey\SciTE\SciTE.exe" "%1"

NOTE: SciTE4AutoHotkey has an option in the installer to set itself as the default editor for AutoHotkey scripts, so that you do not need to edit the registry manually. Even if SciTE4AutoHotkey is already installed, you can run the installer again to set it as the default editor. Or use the .reg file provided below.

Download SciTE4AutoHotkey .reg file


Sublime Text 3:

"C:\Program Files\Sublime Text 3\sublime_text.exe" "%1"

Download Sublime Text 3 .reg file

Locating the executable file path

If you use a different editor and are not sure what the executable’s file path is, you can typically find it by:

  1. Hit the Windows Key to open the Start Menu.
  2. Type the name of the editor you want to use.
  3. Right-click on the editor and choose Open file location.

    Open the application file location from the Windows Start Menu

  4. That should open up File Explorer.
    1. If File Explorer shows the .exe file, you can use its path.
    2. If File Explorer shows a shortcut to the application, right-click on the shortcut and choose Properties.
      1. In the shortcut properties window, click the Open File Location button to open a new File Explorer window containing the .exe file.

        Open the shortcut file location from the shortcut properties window

  5. Copy the path of the executable file and use that as the value for the registry key.

    Copy the path of the executable file from File Explorer

In this example above, the path to the Visual Studio Code executable is “C:\Users\Dan.Schroeder\AppData\Local\Programs\Microsoft VS Code\Code.exe”.

Other ways to open a script in the default editor

You can also use the following AutoHotkey code to open an ahk script in the default editor:

filePath = C:\Path\To\AutoHotkey\Script.ahk
Run, edit %filePath%,,UseErrorLevel
if (%ErrorLevel% = ERROR)
    Run, "notepad" "%filePath%"

In the code above, if an error occurs trying to open the ahk script in the default editor, it will open in Notepad instead.

Conclusion

Now when you right-click on an AutoHotkey script file and choose Edit Script, it will open in your preferred editor, making your life just a little more convenient.

Hopefully you’ve found this helpful.

Happy scripting!

Shameless Plug: AHK Command Picker is my free open-source project that allows you to use a GUI picker instead of having to remember a ton of keyboard shortcuts for your AutoHotkey scripts and hotkeys. It is essentially a quick launcher for any AutoHotkey code. Check it out if you are interested!

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...