21

I have my default editor for .ahk files set to Notepad++ Portable on my work laptop, but selecting Edit This Script opens files in the standard Windows Notepad.

A post on the AHK forums suggests editing the registry, but I don't see any entries under HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command.

How can I configure AutoHotkey to edit scripts with Notepad++?

Stevoisiak
  • 16,510
  • 19
  • 94
  • 173
  • Did you read throw the rest of that post and try other suggestions? Like using http://www.nirsoft.net/utils/file_types_manager.html – Oleg Aug 10 '17 at 17:28

8 Answers8

28

For whatever reason, the Registry entry doesn't exist by default, but it is recognized by the application once created.

  1. Navigate to HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell in RegEdit.
  2. Right-click the Shell folder, select New > Key and name this Edit.
  3. Right-click the Edit folder, select New > Key and name this Command.
  4. Double click the (Default) string entry in Command.
  5. Paste in "C:\Program Files\Notepad++\Notepad++.exe" "%1" to this window.
  6. Reload AutoHotkey for the changes to take effect.

Note: I don't use Notepad++, but this works for VS Code on my system, and will for N++ as long as the directory information for the executable is correct.


The corresponding .reg file looks like this:

Windows Registry Editor Version 5.00 
[HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command]
@="\"C:\\Program Files\\Notepad++\\notepad++.exe\" \"%1\""
Lilienthal
  • 3,939
  • 9
  • 44
  • 80
David Metcalfe
  • 1,753
  • 21
  • 36
  • 1
    How do you "reload AutoHotKey"? Reloading each AHK script in turn doesn't do it. I can relog, but I'm not clear on how to reload AHK in general. – Trey Aug 29 '18 at 15:55
  • @Trey Right click on the application icon in the taskbar, click Exit. Open AutoHotkey again. Otherwise, you could reload it via the related command: https://autohotkey.com/docs/commands/Reload.htm – David Metcalfe Aug 29 '18 at 20:45
  • 1
    Yes, I tried that, but even after doing reload or quit/restart on each one in sequence, Edit didn't change. Since every AHK script runs its own interpreter, perhaps they're pooling a cache containing this, so I'd have to quit every one and then re-open them? I will try relogging when I can, as that's certainly a lot easier since I have a dozen or so scripts. – Trey Aug 29 '18 at 22:07
  • 2
    I didn't have to reload AHK for this to take effect--just clicking save in the registry editor did it for me. – crazybilly Feb 28 '20 at 16:08
  • We should need to give the full path. subl or subl.exe works in cmd but not in the registry. – Smart Manoj Nov 20 '20 at 06:38
  • This has no effect for me using AHK 1.1.33.02 in Win10, even after a reboot. – Bort Jan 17 '21 at 23:12
  • I feel like there might be some confusion from others around what this is intended to change. To confirm, is this intended to change the Edit This Script button in the system tray, or the Edit context menu item when right-clicking on an .ahk file? – Hashim Aziz Jan 24 '21 at 23:42
  • @HashimAziz Per the original question, the change affects the "Edit This Script" option in AutoHotkey. Changing the context menu when you right-click on a file would require changing registry keys in `HKEY_CLASSES_ROOT\*` or `HKEY_CLASSES_ROOT\Directory` instead of `HKEY_CLASSES_ROOT\AutoHotkeyScript`. – David Metcalfe Jan 25 '21 at 01:09
8

The registry entry in item 5 of the previous answer did not work. I don't even know what the extra %* at the end means, so I simplified it to:

"C:\Program Files\Notepad++\Notepad++.exe" "%1"
Petter Friberg
  • 19,652
  • 9
  • 51
  • 94
0

If you are like me and you are hesitant to modify the registry, there is a way to do this using AutoHotKey code.

This is a method I use to edit the script with a different editor. Although I am using Visual Studio Code, the method is the same no matter which editor you want to use. One caveat though: we can't change the existing "Edit This Script" menu item, since that is considered one of the standard menu items and can't be modified. Instead I am adding a new menu item at the top of the menu that says "Edit With Notepad++".

EditWithNotepadPlusPlus()
{
    Run "C:\Program Files (x86)\Notepad++\notepad++.exe" "%A_ScriptFullPath%"
}

; Remove the standard menu items temporarily
Menu, Tray, NoStandard 
; Add our custom menu item labeled "Edit With Notepad++" 
; and calls the function above
Menu, Tray, Add, Edit With Notepad++, EditWithNotepadPlusPlus 
; Add a separator
Menu, Tray, Add 
; Put the standard menu items back, under our custom menu item
Menu, Tray, Standard 

Note: If you're wondering, the lines Menu, Tray, NoStandard and Menu, Tray, Standard are not required. The reason I use those lines is because by default, Menu, MenuName, Add adds menu items to the bottom of the menu. For aesthetic and practical reasons, I prefer Exit to be the last menu item. So Menu, Tray, NoStandard and Menu, Tray, Standard will cause our menu item to appear at the top.

One added benefit of this method is that if you transfer your scripts to a new computer, it should still work (provided you have Notepad++ installed on the other computer). If you edit the registry, you have to remember to edit the registry again.

Cave Johnson
  • 5,835
  • 5
  • 30
  • 49
  • Just tested, this doesn't work :( There is no entry added to the menu. – Mark Jan 08 '20 at 18:05
  • @Mark weird I have been using this code for a while now and it has worked for me so far. I'll check out why it may not be working later. – Cave Johnson Jan 08 '20 at 19:16
  • @Mark Sorry for late reply, but what if you remove all the other lines except for `Menu, Tray, Add, Edit With Notepad++, EditWithNotepadPlusPlus ` and the `EditWithNotepadPlusPlus` function definition at the top. Those are the minimum things needed for this to work. – Cave Johnson Jan 24 '20 at 15:26
  • @KudosJohnson https://imgur.com/bvQhR6l please see that image, it still doesn't do anything. – Mark Jan 25 '20 at 21:04
0

For AHK version 2, changing the registry didn't work for me (I tried both Computer\HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command and Computer\HKEY_CLASSES_ROOT\.ahk\Shell\Edit\Command), but this did it for me. It adds two menu items to the AHK tray menu after a divider:

EditWithNotepadPlusPlus(*)
{
    Run "C:\Program Files\Notepad++\notepad++.exe " A_ScriptFullPath
}
EditWithVsCode(*)
{
    Run "C:\Program Files\Microsoft VS Code\Code.exe " A_ScriptFullPath
}
A_TrayMenu.Add()
A_TrayMenu.Add("Edit with VS Code", "EditWithVsCode")
A_TrayMenu.Add("Edit with Notepad++", "EditWithNotepadPlusPlus")
return
Jerry
  • 133
  • 1
  • 2
  • 9
0

Using AHK v1.1.3.02 on Win10 with string "C:\Program Files\TextPad 8\TextPad.exe" "%1" worked well.

0

The registry change mentioned in other answers for me worked, but you may want to further add the following flags:

C:\Program Files (x86)\Notepad++\notepad++.exe %1  -multiInst -nosession

These flags will stop Notepad++ from recognizing this window as part of your overall session, so it won't overwrite your normal session history or anything. I don't remember where I first found these solutions but I'm switching computers atm and found them in my registry and noticed they weren't mentioned anywhere in this thread.

R River
  • 43
  • 7
0

Was not working for me, i fixed it by first using the suggestion by R River

C:\Program Files (x86)\Notepad++\notepad++.exe %1  -multiInst -nosession

But this would create a new session each time, so i tried removing the end parameters and it now works.

C:\Program Files (x86)\Notepad++\notepad++.exe %1
-4

Simplest way I've found is to:

  1. Right click the .ahk file
  2. Select "Open with" -> "Choose another app"
  3. Check "Always use this app to open .ahk files"
  4. Then select NotePad++ from the list

If it's not listed select "More Apps" and scroll down to NotePad++. (Mind you this example is Windows 10 specific, but previous versions are very similar.)

Editing the registry is great, don't get me wrong, but it takes longer. It's kinda like using a truck to swat a fly! Anyways, hope this works for you. I use it all the time to set the file associations I want.

Lech Migdal
  • 3,290
  • 3
  • 30
  • 57
  • 5
    If you do this then everytime the script will be opened by NotePad++. Thus if you have a start-up script calling the .ahk file, it will not run the script, but instead open it in NotePad++. – Roald Aug 09 '19 at 06:10