FILES
FRBuddy.ahk ; the script (all you need to download)
Will be made by the script if not present:
sarc.ini ; INI file
frdata.dat ; file that stores find/replace strings in hexified format
frdata.bak ; backup file (for update/delete)
PURPOSE
This script can store Find and Replace combinations for text editors. UltraEdit, Notepad++ and PSPad are supported by default. See the below for more information on how to add your editor if not already in the list.
I realise most editors can remember the last +/-10 Find/Replace items or have macro capabilities, but storing them can be useful if you don't need them very often which means it is not very useful to create a macro or add them to your favourites.
You can also store comments so you can describe what the purpose is, you can search the find, replace and comments making it easier to manage large collections.
Many times I've made a (complex) regexp that I would need again later and I stored them in a text file. But I found it to be annoying to copy them to the F&R input fields, hence this script.
Note: Although I say Editors, it can be used for other programs as well as you can see by the Total Commander INI below. It opens the Find Files dialog and fills the 'Search for' (find) and 'Find text' (replace).
HOW IT WORKS
It stores your F&R strings in a text file - hexified to accommodate multiline & "special" characters like %^{}[] etc - and you can add comments to them as well. After you launch the script you can search(!) in your collection or browse using the Up/Down & PgUp/PgDown keys.
It tries to 'guess' your preferred editor based on the active program when you launch the script, so if you are editing in Notepad++ it will select Notepad++ as target editor.
If you prefer you can choose another editor and it will try to activate that editor (which has to be opened, it does not start the editor). You can also LOCK any editor to be the default editor.
Note: It doesn't execute the F&R action, so you can check the settings before you run it.
SHORTCUTS
There are a number of keyboard shortcuts:
F1 = Help
CTRL-Delete or F8 = Delete currently selected row
Enter = Select
Up/Down & Page Up/Page Down = navigate results
ADDING FIND/REPLACE STRINGS
If you click the ADD button you can enter the F&R strings and add a comment.
If your Find and Replace dialog is open it will try to copy the information from it and fill it in for you.
If you EDIT a string, a backup is made of the old list in frdata.bak
EXTRA (using the %_evar_% variable)
There is one special variable you can use in the Find and/or Replacement strings called %_evar_%
If you run the script, you will see you can enter text in the Extra input field. This text can either be a shorthand or can be used as entered.
Shorthand examples:
ds = Date short
dl = Date long
t = time
If you include the special %_evar_% variable somewhere in your FIND or REPLACE string you can insert 'extra' text at the point. Example for the replacement string:
'This document was last updated on %_evar_%'
if you would enter 'ds' (without the ') in the extra input field, it will replace %_evar_% with 3/21/2009 so the entire replacement string that is sent to your editor will be:
'This document was last updated on 3/21/2009'
See the ButtonSelect routine in the script for other examples and to add your own.
STRUCTURE OF THE INI FILE - OR HOW TO ADD ANOTHER EDITOR
If you want to add another editor, just create a new Editor Name as [Section] and use the AHK Window Spy to find the following values:
EditorWindowClass=
-> ahk_class of your editor (must NOT include the text ahk_class)
FRWindowName=
-> WinTitle of the F&R window, CAN include ahk_class
FindClassNN=
-> ClassNN of the Edit control for Find, Edit1 in most cases
ReplaceClassNN=
-> ClassNN of the Edit control for Replace, Edit2 in most cases
Shortcut=
-> The key combination to start F&R in the editor, usually CTRL-R or CTRL-H
EXAMPLE
[Notepad++]
EditorWindowClass=Notepad++
Shortcut=^h
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
Editors in this INI:
- UltraEdit-32*
- Notepad++
- PSPad
On the forum you will find more for:
- Total Commander
- Metapad
- NoteTab Light
- SciTE
- ConText
* see 'BUGS'
'BUGS'
- I have hardcoded an exception for UltraEdit 13+, the reason for this is that UE seems to change its classes each times it launches, although I could perhaps use SetTitleMatchMode, Regex I couldn't be bothered to fix it
TODO
- Nothing I can think of - other than adding more editors
If you're curious after a while on how many times you actualy used it, in the INI you will find the key USED in the SETTINGS section.
CREDITS (see script for references (Rajat, Laszlo, Skan))
The Script:
Code:
; Find & Replace Buddy
; FRBuddy.ahk
; http://www.autohotkey.com/forum/viewtopic.php?t=42971
;
; Credits:
;
; - 320mph by Rajat - you'll recognize the GUI & Search bits and pieces :-)
; http://www.autohotkey.com/forum/topic3010.html
; - String2hex, Laszlo (there are various versions (of hexify) on the forum
; http://www.autohotkey.com/forum/topic4934-15.html#158672
; search the forum, also by Rajat if you are interested)
; I just fiddled around a bit until I got the results I wanted :-)
; - SKAN for Parent ID DLL wizardry
; http://www.autohotkey.com/forum/topic29852.html
; - and probably more which I forgot
;
; Notes:
; - jEdit would need alternative method for sending find / replace (no classes!
; not that difficult, but I don't need it)
; - UltraEdit is hardcoded fix, can't be bothered to ... :-)
; - I start the script via a hotkey (^#R) but I leave that up to your own preference
; - It also works with MS Word but it sometimes fails ...
#SingleInstance force
SetBatchLines, -1
SetKeyDelay, -1
SetTitleMatchMode, 2
; INI section -----------------------------------------------------------------
; Get some info from currently active window (parent of...)
ID := DllCall("GetParent", UInt,WinExist("A")), ID := !ID ? WinExist("A") : ID ; thanks SKAN http://www.autohotkey.com/forum/topic29852.html
WinGetClass, Active_Parent_Window_Class, ahk_id %id%
WinGetTitle, Active_Parent_Window_Title, ahk_id %id%
WinGet, Active_Parent_Process, ProcessName ; for UltraEdit only, see later
CreateINI()
MainWnd=FRBuddy
Version=v0.2
LastText=fadsfSDFDFasdFdfsadfsadFDSFDf
; Various widths, heights & positions for the GUI
GuiWMinus=20
GuiHMinus=250
GuiW:=A_ScreenWidth-GuiWMinus
GuiH:=A_ScreenHeight-GuiHMinus
LVGuiW:=GuiW - 12
LVGuiH:=GuiH - 64
StatusY:=GuiH - 22
ColW:=Ceil(LVGuiW/3)
wInput:=ColW-150
wPadding:=wInput+5
xSelect:=GuiW-241
xAdd:=GuiW-180
xEdit:=GuiW-120
xHelp:=GuiW-58
VisibleRows:=Ceil(LVGuiH/15) ; for pagedown/pageup
; Read Editors from INI file
CreateINI()
FileRead, FullINI, %A_ScriptDir%\sarc.ini
Loop, Parse, FullINI,`r,`n
{
RegExMatch(A_LoopField, "\[(.*)]$",Section) ; yes just InStr is probably faster
If (Section1 <> "")
Sections.= "|" Section1
}
StringTrimLeft, Sections, Sections, 10 ; trim first section [settings]
IniRead, Lock, %A_ScriptDir%\sarc.ini, Settings, Lock
IniRead, Editor, %A_ScriptDir%\sarc.ini, Settings, Editor
; Get list of editors
Loop, Parse, Sections, |
{
IniRead, ReadTemp, %A_ScriptDir%\sarc.ini, %A_LoopField%, EditorWindowClass
EditorClasses.="|" ReadTemp
If (Lock = 1) AND (Editor = A_LoopField)
StringReplace,Sections,Sections,%A_LoopField%,%A_LoopField%| ; make the chosen editor the selected one in the dropdownlist
Else
{
If (Active_Parent_Window_Class = ReadTemp)
StringReplace,Sections,Sections,%A_LoopField%,%A_LoopField%| ; make the chosen editor the selected one in the dropdownlist
}
ReadTemp=
}
; we need to make an exeption for UltraEdit, it's class is constantly changing the last 5 characters, crude hack I know
Ultra:="uedit32" . "." . "exe"
If (Active_Parent_Process = Ultra)
StringReplace,Sections,Sections,UltraEdit,UltraEdit|
StringTrimLeft, EditorClasses, EditorClasses, 1 ; trim first |
If (Lock=1)
Checked=Checked
Else
Checked=""
; Gui -------------------------------------------------------------------------
GuiStart:
Gui , 1:Add, Text, x6 y10 w40 h20, Search:
Gui , 1:Add, Edit, x46 y7 w%wInput% h20 vCurrText gGetText,
Gui , 1:Add, Text, xp+%wPadding% y10 w40 h20, Extra:
Gui , 1:Add, Edit, xp+30 y7 w%wInput% h20 vExtra,
Gui , 1:Add, Text, xp+%wPadding% y10 w40 h20, Editor:
Gui , 1:Add, DropDownList, Sort xp+35 y6 w125 vSettings_Editor r10, %Sections%
Gui , 1:Add, Checkbox, 0x8000 xp+130 y10 vLock gLock %checked%, Loc&k
Gui , 1:Add, Button, 0x8000 x%xSelect% y7 w50 h20 Default, &Select
Gui , 1:Add, Button, 0x8000 x%xAdd% y7 w50 h20, &Add
Gui , 1:Add, Button, 0x8000 x%xEdit% y7 w50 h20, &Edit
Gui , 1:Add, Button, 0x8000 x%xHelp% y7 w50 h20, &Help
Gui , 1:Add, ListView, x6 y35 w%LVGuiW% h%LVGuiH% Grid ReadOnly HScroll -0x200000 gSelection,Find|Replace|Comment
Gosub, PopulateList
Gui , 1:Add, Text, x6 y%StatusY% w120 h20 vResults, Results = %Lines%
Gui , 1:Add, Text, xp+675 y%StatusY% w600 h20, %MainWnd% - %version%
Gui , 1:Show, h%GuiH% w%GuiW%, %MainWnd%
Gosub, GetText
Return
; -----------------------------------------------------------------------------
PopulateList:
LV_Delete() ; clear listview
Lines=
FileRead, GetList, %A_ScriptDir%\frdata.dat
Loop, Parse, GetList, `r,`n
{
If (A_LoopField <> "") ; skip empty lines if any
{
StringSplit,C,A_LoopField,|
Convert("h2s",c1,c2,c3)
Col1_%A_Index%:=cv1
Col2_%A_Index%:=cv2
Col3_%A_Index%:=cv3
LV_Add("",Col1_%A_Index%,Col2_%A_Index%,Col3_%A_Index%)
Lines=%A_Index%
}
}
LV_ModifyCol(1, ColW+5)
LV_ModifyCol(2, ColW+5)
LV_ModifyCol(3, ColW-30)
LV_ModifyCol(3, "Sort")
GuiControl,, Results, Results = %Lines%
GetList= ; clear
Return
; Search ----------------------------------------------------------------------
GetText:
HitList=
MinLen=1
ControlGetText, CurrText, Edit1, %MainWnd%
IfEqual, CurrText, %LastText%
{
IfLess, Results, %Lines%
Gosub PopulateList ; if Edit1 is empty again after del or backspace "restart"
Return
}
StringLen, Check, CurrText
IfLess, Check, %MinLen%
{
Gosub PopulateList ; if Edit1 is empty again after del or backspace "restart"
Return
}
ControlGetText, CurrText, Edit1, %MainWnd%
LastText = %CurrText%
IfNotEqual, CurrText, %LastText%, Goto, GetText
Loop, %lines%
{
FullLine:=Col1_%A_Index% . A_Space . Col2_%A_Index% . A_Space . Col3_%A_Index%
IfInString, FullLine, %CurrText%
Hitlist.= "|" A_Index
}
StringTrimLeft, Hitlist, Hitlist, 1 ; remove first |
LV_Delete() ; clear listview
Loop, Parse, Hitlist, |
LV_Add("",Col1_%A_LoopField%,Col2_%A_LoopField%,Col3_%A_LoopField%)
LastText =
Results := LV_GetCount()
GuiControl,, Results, Results = %Results%
Return
; Keys ------------------------------------------------------------------------
Esc::
Goto, GuiClose
Return
Down::
IfWinNotActive, %MainWnd%,
{
Send, {Down}
Return
}
ControlGetFocus, CurrCtrl, %MainWnd%
IfEqual, CurrCtrl, Edit1
ControlSend, SysListView321, {Down}, %MainWnd%
IfEqual, CurrCtrl, ComboBox1
ControlSend, ComboBox1, {Down}, %MainWnd%
Return
Up::
IfWinNotActive, %MainWnd%,
{
Send, {Up}
Return
}
ControlGetFocus, CurrCtrl, %MainWnd%
IfEqual, CurrCtrl, Edit1
ControlSend, SysListView321, {Up}, %MainWnd%
IfEqual, CurrCtrl, ComboBox1
ControlSend, ComboBox1, {Up}, %MainWnd%
Return
Pgdn::
IfWinNotActive, %MainWnd%,
{
Send, {PgDn}
Return
}
ControlGetFocus, CurrCtrl, %MainWnd%
IfEqual, CurrCtrl, Edit1
ControlSend, SysListView321, {Down %VisibleRows%}, %MainWnd%
Return
Pgup::
IfWinNotActive, %MainWnd%,
{
Send, {Pgup}
Return
}
ControlGetFocus, CurrCtrl, %MainWnd%
IfEqual, CurrCtrl, Edit1
ControlSend, SysListView321, {Up %VisibleRows%}, %MainWnd%
Return
^Del::
F8::
Gui, 1:Submit, NoHide
ControlFocus, SysListView321, %MainWnd%
SelItem := LV_GetNext()
If (SelItem = 0)
SelItem = 1
LV_GetText(Find, SelItem, 1)
LV_GetText(Replace, SelItem, 2)
LV_GetText(Comments, SelItem, 3)
Gui, 1:Destroy
ScriptHotkeys() ; Toggle hotkeys
MsgBox, 33, Delete, Do you want to delete:`r`n`r`nF: %Find%`r`nR: %Replace%`r`nC: %Comments%
IfMsgBox OK
{
AutoTrim, On
FileMove, %A_ScriptDir%\frdata.dat, %A_ScriptDir%\frdata.bak, 1 ; create backup
Convert("s2h",Find,Replace,Comments)
DeleteLine=%cv1%|%cv2%|%cv3%
Loop, Read, frdata.bak, %A_ScriptDir%\frdata.dat
{
ReadLine=%A_LoopReadLine% ; to trim any trailing spaces
IfNotEqual, ReadLine, %DeleteLine%, FileAppend, %ReadLine%`r`n
}
DeleteLine=
ReadLine=
}
ScriptHotkeys() ; Toggle hotkeys
Reload
Return
F1::
Gosub ButtonHelp
Return
; Buttons ---------------------------------------------------------------------
ButtonSelect:
Gui , 1:Submit, NoHide
ControlFocus, SysListView321, %MainWnd%
SelItem := LV_GetNext()
If (SelItem = 0)
SelItem = 1
LV_GetText(Find, SelItem, 1)
LV_GetText(Replace, SelItem, 2)
Gui, 1:Destroy
CheckExtra=%Find%%Replace% ; quick & dirty method, could be nicer
IfInString, CheckExtra, `%_evar_
{
; just some examples what you could do with %_evar_%
IfEqual, Extra, dl
FormatTime, Extra, , LongDate
IfEqual, Extra, ds
FormatTime, Extra, , ShortDate
IfEqual, Extra, t
FormatTime, Extra, , Time
;IfEqual, Extra, x
; Extra=_eXample_
; If nothing special found, just use the extra text as entered
StringReplace, Find, Find, `%_evar_`%, %Extra%
StringReplace, Replace, Replace, `%_evar_`%, %Extra%
}
ReadEditorSetting()
If (Settings_Editor = "UltraEdit") ; exception for UltraEdit
WinActivate, UltraEdit,,1
Else
{
IfWinNotExist, ahk_class %EditorWindowClass%
{
MsgBox,48,Failed, %Settings_Editor% not running.`r`nClosing %MainWnd%.
Goto, GuiClose
}
WinActivate, ahk_class %EditorWindowClass%
}
Send, %ShortCut%
WinWaitActive, %FRWindowName%,,2
If ErrorLevel
{
MsgBox,48,Failed, Find `& Replace command unsuccessful.`r`nClosing %MainWnd%.
Goto, GuiClose
}
Else
{
ControlSetText, %FindClassNN%, %Find%, %FRWindowName%
ControlSetText, %ReplaceClassNN%, %Replace%, %FRWindowName%
IniRead, Used, %A_ScriptDir%\sarc.ini, Settings, Used
Used += 1
IniWrite, %Used%, %A_ScriptDir%\sarc.ini, Settings, Used
}
Goto, GuiClose
Return
; mouse event -----------------------------------------------------------------
Selection:
IfEqual, A_GuiControlEvent, DoubleClick
GoTo, ButtonSelect
Return
ButtonAdd:
Gui, 1:Submit
ReadEditorSetting()
ControlGetText, Find, %FindClassNN%, %FRWindowName%
ControlGetText, Replace, %ReplaceClassNN%, %FRWindowName%
StringReplace, Find, Find, `n, `r`n, all
StringReplace, Replace, Replace, `n, `r`n, all
Gui, 20:Add, Text, x10 y10 w100 h20, Find:
Gui, 20:Add, Edit, x70 y10 w400 r1 -Multi vFind, %Find%
Gui, 20:Add, Text, x10 y40 w100 h20, Replace:
Gui, 20:Add, Edit, x70 y40 w400 r1 -Multi vReplace, %Replace%
Gui, 20:Add, Text, x10 y70 w100 h20, Comments:
Gui, 20:Add, Edit, x70 y70 w400 r1 -Multi vComments,
Gui, 20:Add, Button, x70 y100 w70 H25 gButtonSave Default, &Save
Gui, 20:Add, Button, x150 y100 w70 H25 gButtonCancel, &Cancel
Gui, 20:Show
Return
ButtonSave:
Gui, 20:Submit
Gui, 20:Destroy
Convert("s2h",Find,Replace,Comments)
FileAppend,%cv1%|%cv2%|%cv3%`r`n, %A_ScriptDir%\frdata.dat
Reload
Return
ButtonCancel:
Gui, 20:Destroy
Gui, 1:Show
Return
ButtonEdit:
Gui, 1:Submit
ControlFocus, SysListView321, %MainWnd%
SelItem := LV_GetNext()
If (SelItem = 0)
SelItem = 1
LV_GetText(Find, SelItem, 1)
LV_GetText(Replace, SelItem, 2)
LV_GetText(Comments, SelItem, 3)
Convert("s2h",Find,Replace,Comments)
DeleteLine=%cv1%|%cv2%|%cv3% ; we need this so we can replace it
Gui, 40:Add, Text, x10 y10 w100 h20, Find:
Gui, 40:Add, Edit, x70 y10 w400 r1 -Multi vFind, %Find%
Gui, 40:Add, Text, x10 y40 w100 h20, Replace:
Gui, 40:Add, Edit, x70 y40 w400 r1 -Multi vReplace, %Replace%
Gui, 40:Add, Text, x10 y70 w100 h20, Comments:
Gui, 40:Add, Edit, x70 y70 w400 r1 -Multi vComments, %Comments%
Gui, 40:Add, Button, x70 y100 w70 H25 gButtonUpdate Default, &Update
Gui, 40:Add, Button, x150 y100 w70 H25 gButtonCancel, &Cancel
Gui, 40:Show
Return
ButtonUpdate:
Gui, 40:Submit
StringReplace,Find,Find,`n,`r`n,All ; The edit control removes the `r so we need to add it back in case of multiline
StringReplace,Replace,Replace,`n,`r`n,All ; The edit control removes the `r so we need to add it back in case of multiline
Convert("s2h",Find,Replace,Comments)
ReplaceLine=%cv1%|%cv2%|%cv3%
ScriptHotkeys()
MsgBox, 33, Update, Do you want to Update this entry:`r`n`r`nF: %Find%`r`nR: %Replace%`r`nC: %Comments%
IfMsgBox OK
{
AutoTrim, On
FileMove, %A_ScriptDir%\frdata.dat, frdata.bak, 1 ; create backup
Loop, Read, frdata.bak, %A_ScriptDir%\frdata.dat
{
ReadLine=%A_LoopReadLine% ; to trim any trailing spaces
IfEqual, ReadLine, %DeleteLine% ; found the old one, replace with new one
FileAppend, %ReplaceLine%`r`n
Else ; keep this line
FileAppend, %ReadLine%`r`n
}
DeleteLine=
ReadLine=
ReplaceLine=
}
ScriptHotkeys()
Reload
Return
Lock: ; set specific editor as default
GuiControlGet, Status, , Button1
IniWrite, %Status%, %A_ScriptDir%\sarc.ini, Settings, Lock
GuiControlGet, EditorSave, , ComboBox1
IniWrite, %EditorSave%, %A_ScriptDir%\sarc.ini, Settings, Editor
ControlFocus, Edit1, %MainWnd%
Return
ButtonHelp:
;Gui, 1:Hide
HelpText =
(
Forum
------------------------------------------------------------------------------------
More information at the AHK forum
http://www.autohotkey.com/forum/viewtopic.php?t=42971
Some basic info below.
Keys
------------------------------------------------------------------------------------
F1 = Help
CTRL-Delete or F8 = Delete currently selected row
Enter = Select
Up/Down & PgUP/PgDOWN = navigate results
Structure of the INI file - or how to Add another Editor
------------------------------------------------------------------------------------
If you want to add another editor, just create a new
Editor Name as [Section] and use the AHK Window Spy
to find the following values:
EditorWindowClass=
-> ahk_class of your editor (must NOT include the text ahk_class)
FRWindowName=
-> WinTitle of the F&R window, CAN include ahk_class
FindClassNN=
-> ClassNN of the Edit control for Find, Edit1 in most cases
ReplaceClassNN=
-> ClassNN of the Edit control for Replace, Edit2 in most cases
Shortcut=
-> The key combination to start F&R
Example:
[Notepad++]
EditorWindowClass=Notepad++
Shortcut=^h
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
More at the AHK forum.
)
Gui , 90:+Toolwindow
Gui , 90:Add, Edit, w300 H405 ReadOnly WantCtrlA, %HelpText%
Gui , 90:Show, w320 h420, %MainWnd% - Help
Send ^{Home} ; sends cursor to top in Edit
Return
; Functions -------------------------------------------------------------------
; Check INI -------------------------------------------------------------------
CreateINI() ; create ini on first run if it does not Exist
{
IniFile = %A_ScriptDir%\sarc.ini
IfNotExist, %IniFile%
{
{
ini=
(
[Settings]
Lock=0
Editor=Notepad++
Used=0
[UltraEdit]
EditorWindowClass=Afx\:00400000\:8\:00010013\:00000000\:.*
Shortcut=^r
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
[Notepad++]
EditorWindowClass=Notepad++
Shortcut=^h
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
[PSPad]
EditorWindowClass=TfPSPad
Shortcut=^h
FRWindowName=Replace ahk_class TfFindReplace
FindClassNN=Edit2
ReplaceClassNN=Edit1
)
FileAppend,%ini%,%IniFile%
ini=
}
}
}
; Read INI for Editor ---------------------------------------------------------
ReadEditorSetting()
{
Global
IniRead, EditorWindowClass, %A_ScriptDir%\sarc.ini, %Settings_Editor%, EditorWindowClass
IniRead, Shortcut , %A_ScriptDir%\sarc.ini, %Settings_Editor%, Shortcut
IniRead, FRWindowName , %A_ScriptDir%\sarc.ini, %Settings_Editor%, FRWindowName
IniRead, FindClassNN , %A_ScriptDir%\sarc.ini, %Settings_Editor%, FindClassNN
IniRead, ReplaceClassNN , %A_ScriptDir%\sarc.ini, %Settings_Editor%, ReplaceClassNN
}
; -----------------------------------------------------------------------------
ScriptHotkeys()
{
Hotkey, Up , Toggle, UseErrorLevel
Hotkey, Down, Toggle, UseErrorLevel
Hotkey, ^Del, Toggle, UseErrorLevel
Hotkey, F1 , Toggle, UseErrorLevel
Hotkey, F8 , Toggle, UseErrorLevel
}
; Convert 2 and from hex ------------------------------------------------------
Convert(direction,c1,c2,c3)
{
Global
If (direction = "s2h")
{
cv1:=String2Hex(c1)
cv2:=String2Hex(c2)
cv3:=String2Hex(c3)
}
If (direction = "h2s")
{
cv1:=Hex2String(c1)
cv2:=Hex2String(c2)
cv3:=Hex2String(c3)
}
Return
}
; -----------------------------------------------------------------------------
; Reference http://www.autohotkey.com/forum/topic4934-15.html#158672
String2Hex(x) ; Convert a string to hex digits (modified to accommodate new line chars)
{
prevFmt = %A_FormatInteger%
SetFormat Integer, H ;this function requires hex format
Loop Parse, x
hex .= 0x100+Asc(A_LoopField)
StringReplace hex, hex, 0x1,,All
SetFormat Integer, %prevFmt% ;restore original integer formatting
Return hex
}
Hex2String(x) ; Convert a huge hex number to string (modified to suite String2Hex above)
{
Loop % StrLen(x)/2
{
Pos:=(A_Index-1)*2+1
StringMid hex, x, Pos, 2
string := string . Chr("0x" hex)
}
Return string
}
; -----------------------------------------------------------------------------
GuiClose:
GuiExit:
ExitApp
; the end ---------------------------------------------------------------------
If you don't save the INI below, the script will create a
default INI with UltraEdit, Notepad++ and PSPad support.
INI:
Code:
[Settings]
Lock=0
Editor=Notepad++
Used=0
[UltraEdit]
EditorWindowClass=Afx\:00400000\:8\:00010013\:00000000\:.*
Shortcut=^r
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
[Notepad++]
EditorWindowClass=Notepad++
Shortcut=^h
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
[PSPad]
EditorWindowClass=TfPSPad
Shortcut=^h
FRWindowName=Replace ahk_class TfFindReplace
FindClassNN=Edit2
ReplaceClassNN=Edit1
[Microsoft Word 97]
EditorWindowClass=OpusApp
Shortcut=^h
FRWindowName=Find and Replace ahk_class bosa_sdm_Microsoft Word 8.0
FindClassNN=RichEdit20W1
ReplaceClassNN=RichEdit20W2
[Microsoft Word 2000]
EditorWindowClass=OpusApp
Shortcut=^h
FRWindowName=Find and Replace ahk_class bosa_sdm_Microsoft Word 9.0
FindClassNN=RichEdit20W1
ReplaceClassNN=RichEdit20W2
[Total Commander]
EditorWindowClass=TTOTAL_CMD
Shortcut=!{F7}
FRWindowName=Find Files ahk_class TFindFile
FindClassNN=Edit3
ReplaceClassNN=Edit1
[Metapad]
EditorWindowClass=metapad
Shortcut=^h
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
[NoteTab Light]
EditorWindowClass=TfrmNoteTab
Shortcut=^r
FRWindowName=Find and Replace ahk_class TfrmReplace
FindClassNN=Edit2
ReplaceClassNN=Edit1
[SciTE]
EditorWindowClass=SciTEWindow
Shortcut=^h
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2
[ConText]
EditorWindowClass=TfmMain
Shortcut=^r
FRWindowName=Replace Text ahk_class TfmFind
FindClassNN=Edit1
ReplaceClassNN=Edit2
[NotePad2]
EditorWindowClass=Notepad2
Shortcut=^h
FRWindowName=Replace ahk_class #32770
FindClassNN=Edit1
ReplaceClassNN=Edit2