Execute N++ "Find in Files" via cmdline/script?
Love the product, but curious to know if it is possible to execute the “Find in Files” from the command-line / batch / vbscript.
The output seen within N++ is something I like and I’d like to incorporate this output for some automated tasks if possible.
not 100% sure what you want to achieve.
Do you have some automated tasks while npp is not running at all
and at some step you do want to search something in files and the
output should be similar to the one npp shows
do you have npp running, do something and then you want to run
find in files dialog and this output should be forwarded to
some automated task?
Maybe you wanna describe in more detail what exactly you want to do.
I also am not sure what @Cameron-Young is really wanting to do, but it got me to thinking about how to handle Find-in-Files output programmatically “within” Notepad++ via Pythonscript.
I came up with the following that will get the textual contents of the Find result panel (based upon the code ideas here–a pretty shallow rip-off in fact!). This could be prefaced with setting the Find dialog’s control fields and pressing the Find-in-Files (or Find-All-…) button (pressing a button example here) under program control. Once you have the output text, it can be parsed at will to do whatever is needed from that.
import ctypes from ctypes.wintypes import BOOL, HWND, LPARAM WNDENUMPROC = ctypes.WINFUNCTYPE(BOOL, HWND,LPARAM) FindWindow = ctypes.windll.user32.FindWindowW GetWindowText = ctypes.windll.user32.GetWindowTextW GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW EnumChildWindows = ctypes.windll.user32.EnumChildWindows GetClassName = ctypes.windll.user32.GetClassNameW curr_class = ctypes.create_unicode_buffer(256) find_result_panel_complete_text = '' def foreach_window(hwnd, lParam): global find_result_panel_complete_text length = GetWindowTextLength(hwnd) if length > 0: buff = ctypes.create_unicode_buffer(length + 1) GetWindowText(hwnd, buff, length + 1) if buff.value.startswith('Search "'): # perhaps change to more rigorous test... find_result_panel_complete_text = buff.value return False return True EnumChildWindows(FindWindow(u'Notepad++', None), WNDENUMPROC(foreach_window), 0) editor.copyText(find_result_panel_complete_text) # result in clipboard
nice one and could be already half the solution. :-)
Maybe we should think about python_automation_api_for_npp ;-)
Maybe not an all-encompasing automation API, but one focused on the ever-controversial Find functionality…
Are you up for a joint project with me on this?
in general yes, but not for the moment, currently I’m doing 3 projects in parallel
And I don’t see that this progresses. :-)