Change the default AutoHotkey script editor
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.
The same is true when using the Edit This Script
option from the context menu of the tray icon for a running script.
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:
- Press
Windows Key
+R
to access the Run dialog. - Type
regedit
and hit OK to open the Registry Editor. - Navigate to
HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command
. - 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:
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:
- Navigate to
HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell
in the Registry Editor. - Right-click the
Shell
folder, selectNew
>Key
and name thisEdit
. - Double-click the
(Default)
entry in the newEdit
folder, and set its value toEdit Script
. - Right-click the
Edit
folder, selectNew
>Key
and name thisCommand
. - The
(Default)
entry should now exist in the newCommand
folder, and you should be able to set its value as described above.
Registry values and download files for popular AutoHotkey script editors
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.
"C:\Program Files\Notepad++\notepad++.exe" "%1"
"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.
"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
"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:
- Hit the
Windows Key
to open the Start Menu. - Type the name of the editor you want to use.
-
Right-click on the editor and choose
Open file location
. - That should open up File Explorer.
- If File Explorer shows the .exe file, you can use its path.
- If File Explorer shows a shortcut to the application, right-click on the shortcut and choose
Properties
.-
In the shortcut properties window, click the
Open File Location
button to open a new File Explorer window containing the .exe file.
-
-
Copy the path of the executable file and use that as the value for the registry key.
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 *