Jump to content


Photo

Change the notepad.exe systemwide to a better editor


  • Please log in to reply
1 reply to this topic

#1 Timo

Timo
  • Members
  • 26 posts

Posted 24 March 2012 - 04:24 PM

Hi,

using the Autohotkey as a portable package does give some pain, for example the menu item 'Edit This Script ' does it with Notepad. And as it is well known it is a little bit difficult to change the default txt editor of M$ Windows. But I want to use a better one so I cooked up the below solution. It is using the Debugger registry trick (adds one registry entry) and works perfectly on XP. Even opens multiple files from Windows Explorer to the Notepad++.

First compile the below as NotepadChanger.exe and then save that exe to the %systemroot% folder (usually C:\winNT or C:\windows):
#NoTrayIcon

Loop, %0%
{
if A_Index = 1
{
	EditorFullpath := %A_Index%
}
else if A_Index > 2
{
    param := param A_Space %A_Index%
}
}
param :=  Trim(param)
run, %EditorFullpath% %param%
ExitApp

then run this script:
FileSelectFile, SelectedFile, 3, , Browse to and Select the Executable of Your Favorite Text Editor:, Executable (*.exe)

SplitPath, SelectedFile, OutFileName

if SelectedFile =
{
    MsgBox, User cancelled, no actions taken.
}
else if OutFileName = notepad.exe
{
	Msgbox, notepad.exe would create a infinite loop.`n`nExit with no actions taken.
	ExitApp
}


else
{
	RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe, Debugger, NotepadChanger.exe "%SelectedFile%"
	RegRead, RegEntry, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe, Debugger
	msgbox, The following Registy entry was created:`n`nKEY: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options`nSUBKEY: notepad.exe`nVALUE: Debugger`nDATA: %regEntry%
	}
ExitApp

With Best Regards,
Timo

#2 Timo

Timo
  • Members
  • 26 posts

Posted 03 April 2012 - 08:56 AM

Aha, a small correction as it did not work with SciTE. Now tested OK with SciTE, Notepad++, and Notepad2. Opens multiple selections to as many main windows, not into tabs.

First compile the below as NotepadChanger.exe and then save that exe to the %windir% folder (usually C:\winNT or C:\windows):
#NoTrayIcon

Loop, %0%
{
if A_Index = 1
{
	EditorFullpath := %A_Index%
}
else if A_Index > 2
{
    param := param A_Space %A_Index%
}
}
param :=  Trim(param)
run, %EditorFullpath% "%param%"
ExitApp

then run this script:
FileSelectFile, SelectedFile, 3, , Browse to and Select the Executable of Your Favorite Text Editor:, Executable (*.exe) 
SplitPath, SelectedFile, OutFileName 
if SelectedFile = 
{
MsgBox, User cancelled, no actions taken. 
} 
else if OutFileName = notepad.exe
{
Msgbox, notepad.exe would create a infinite loop.`n`nExit with no actions taken.
}
ExitApp

And if you ever want to revert back to MS Notepad, run this:
RegDelete, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe, Debugger
ExitApp