Hello Tuska,
there is one downside: this requires a script, and the script is configured for a German interface.
You need to create two files in the folder:
Notepad++\plugins\PythonScript\scripts:
startup.py
commandlineSearch27472.py
The
startup.py should contain the following:
Code: Select all
from Npp import *
import sys
console.write("Versuche Import...\n")
try:
import commandlineSearch27472
console.write("IMPORT OK\n")
except Exception as e:
console.write("IMPORT FEHLER: " + str(e) + "\n")
and the
commandlineSearch.py the following:
I am not the author of this script — I only modified it until it worked without errors for me.
Code: Select all
# -*- coding: utf-8 -*-
"""in response to https://community.notepad-plus-plus.org/topic/27472/
(fixed URL to Topic)
process -pluginMessage="PythonScriptCommandlineSearch=term"
`term` must be a normal search term, not a regular expression; it currently cannot include semicolons `;` or double-quotes `"`
updated version for German localization
"""
##### -------
##### Instructions:
#####
##### {these assume a normal installation of Notepad++, using %AppData%\Notepad++ for user configuration}
#####
##### See [PythonScript FAQ](https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript)
#####
##### - Create `%AppData%\Notepad++\plugins\PythonScript\scripts\commandlineSearch27472.py`, from the contents below
##### - Check for menu entry **Plugins > Python Script > Scripts > startup (User)**
##### - if it is listed, `Ctrl+click` on it to edit, and add the following to the end:
##### - if it isn't listed, create `%AppData%\Notepad++\plugins\PythonScript\scripts\user.py` from the contents below
##### - set **Plugins > Python Script > Configuration...** to **Initialisation: `ATSTARTUP`**
##### - exit and restart Notepad++
#####
##### After doing that, the script should look for
##### `notepad++ -pluginMessage="PythonScriptCommandlineSearch=term"`, and run a search for `term`
#####
##### For now, it won't work with semicolon `;` or double-quote `"` in the search term;
##### if that is needed, I would need to add an escape sequence processing, which would make it more complicated.
##### -------
from Npp import console
console.write(">>> commandlineSearch27472 geladen <<<\n")
from Npp import notepad, console, NOTIFICATION, MENUCOMMAND
import ctypes
import sys
import re
import time
import ctypes
from ctypes.wintypes import HWND, UINT, WPARAM, LPARAM, HMODULE, LPCWSTR, LPCSTR, LPVOID
def usePluginMessageString27472de(s):
m = re.search(r'PythonScriptCommandlineSearch=([^;"]+)', s)
# ✅ Prüfung hinzufügen
if not m:
console.write("FEHLER: Suchterm nicht gefunden in: '%s'\n" % s)
return
t = m.group(1)
# Define the functions and constants needed
FindWindow = ctypes.windll.user32.FindWindowW
FindWindow.argtypes = [LPCWSTR, LPCWSTR]
FindWindow.restype = HWND
FindWindowEx = ctypes.windll.user32.FindWindowExW
FindWindowEx.argtypes = [HWND, HWND, LPCWSTR, LPCWSTR]
FindWindowEx.restype = HWND
SendMessageStr = ctypes.windll.user32.SendMessageW
SendMessageStr.argtypes = [HWND, UINT, WPARAM, LPCWSTR]
SendMessageStr.restype = LPARAM
SendDlgItemMessage = ctypes.windll.user32.SendDlgItemMessageW
SendDlgItemMessage.argtypes = [HWND, UINT, UINT, WPARAM, LPARAM]
SendDlgItemMessage.restype = LPARAM
WM_SETTEXT = 0x000C
BM_CLICK = 0x00F5
# see https://community.notepad-plus-plus.org/post/59785 for VB.net inspiration
notepad.menuCommand(MENUCOMMAND.SEARCH_FIND)
hFindWnd = None
# try 10 times
for i in range(10):
hFindWnd = FindWindow("#32770", "Find")
if not hFindWnd:
hFindWnd = FindWindow("#32770", "Suchen")
if not hFindWnd:
hFindWnd = FindWindow("#32770", "Suchen und ersetzen")
if hFindWnd:
break
time.sleep(0.2) # wait for the Find window to appear
hComboBx = FindWindowEx(hFindWnd, 0, "ComboBox", None) if hFindWnd else 0
hFindStr = FindWindowEx(hComboBx, 0, "Edit", None) if hComboBx else 0
SendMessageStr(hFindStr, WM_SETTEXT, 0, t)
time.sleep(0.1)
# set search mode:
hNormBtn = None
for i in range(10):
hNormBtn = FindWindowEx(hFindWnd, 0, "Button", "Norma&l")
if hNormBtn:
break
time.sleep(0.2)
if hNormBtn:
SendMessageStr(hNormBtn, BM_CLICK, 0, None)
time.sleep(0.1)
# start search with Enter key using keyboard simulation
console.write("Starte Suche nach: '%s'\n" % t)
# Simulate Enter key press
ctypes.windll.user32.keybd_event(0x0D, 0, 0, 0) # VK_RETURN down
time.sleep(0.05)
ctypes.windll.user32.keybd_event(0x0D, 0, 2, 0) # VK_RETURN up
console.write("Enter-Taste simuliert\n")
# TODO: I'd like to try SendDlgItemMessageW(hFindWnd, ctrlID, BM_CLICK, 0, 0), to avoid having to search for the "Find Next" button
# but using the 1625 from search macros, I couldn't get it to change Search Mode, so just manually click the buttons for now
def getStringFromNotification27472de(args):
code = args['code'] if 'code' in args else None
idFrom = args['idFrom'] if 'idFrom' in args else None
hwndFrom = args['hwndFrom'] if 'hwndFrom' in args else None
#console.write(f"notification(code:{code}, idFrom:{idFrom}, hwndFrom:{hwndFrom}) received\n")
if idFrom is None: return
s = ctypes.wstring_at(idFrom)
#console.write(f"\tAdditional Info: str=\"{s}\"\n")
usePluginMessageString27472de(s)
def getStringFromCommandLine27472de():
for token in sys.argv:
if len(token)>15 and token[0:15]=="-pluginMessage=":
s = token[15:]
#console.write(f"TODO: process {token} => \"{s}\"\n")
usePluginMessageString27472de(s)
notepad.callback(getStringFromNotification27472de, [NOTIFICATION.CMDLINEPLUGINMSG])
console.write("Registered getStringFromNotification27472de callback for CMDLINEPLUGINMSG\n")
getStringFromCommandLine27472de()
You then need to set
Plugins -> Python Script -> Configuration > "Initialization" to "ATSTARTUP" in Notepad++.

- 2026-03-31_171942.png (120.26 KiB) Viewed 10675 times
Once you have done that, it should work.
If it doesn’t… it took me “a bit” to get it working as well… please open the console under the Python configuration and post the output here.