<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How can I pass a search term to Notepad++ via command?]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I wanted to ask if it’s possible to pass a value to Notepad++ that is then immediately searched for and highlighted in the file being opened.</p>
<p dir="auto">Something like this:</p>
<pre><code>notepad++.exe "%1" -(search) "term"
</code></pre>
<p dir="auto">Is there a command, parameter, or plugin that allows this to be automated?</p>
<p dir="auto">Thank you in advance for your help!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/27472/how-can-i-pass-a-search-term-to-notepad-via-command</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 17:26:27 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/27472.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Mar 2026 19:13:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 20:58:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
<p dir="auto">Thank you many times!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105066</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105066</guid><dc:creator><![CDATA[Native2904]]></dc:creator><pubDate>Thu, 26 Mar 2026 20:58:18 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 20:54:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/native2904" aria-label="Profile: Native2904">@<bdi>Native2904</bdi></a> ,</p>
<h3>updated script:</h3>
<pre><code class="language-py"># encoding=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 &gt; Python Script &gt; Scripts &gt; 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 &gt; Python Script &gt; 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 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)
    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

    SendMessage = ctypes.windll.user32.SendMessageW
    SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
    SendMessage.restype  = LPARAM

    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)

    # set search mode:
    hNormBtn = None
    for i in range(10):
        hNormBtn = FindWindowEx(hFindWnd, 0, "Button", "Norma&amp;l")
        if hNormBtn:
            break
        time.sleep(0.2)
    if hNormBtn:
        SendMessageStr(hNormBtn, BM_CLICK, 0, None)

    # start search
    hFindBtn = None
    for i in range(10):
        hFindBtn = FindWindowEx(hFindWnd, 0, "Button", "Näch&amp;stes finden")
        if hNormBtn:
            break
        time.sleep(0.2)
    console.write(f"FindWindows: FIND={hFindWnd:08X} ComboBox={hComboBx:08X} FindNext:{hFindBtn:08X}\n")
    if hFindBtn:
        SendMessageStr(hFindBtn, BM_CLICK, 0, None)

    # 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)&gt;15 and token[0:15]=="-pluginMessage=":
            s = token[15:]
            #console.write(f"TODO: process {token} =&gt; \"{s}\"\n")
            usePluginMessageString27472de(s)

notepad.callback(getStringFromNotification27472de, [NOTIFICATION.CMDLINEPLUGINMSG])
console.write("Registered getStringFromNotification27472de callback for CMDLINEPLUGINMSG\n")
getStringFromCommandLine27472de()
</code></pre>
<p dir="auto">When I have localization=<code>Deutsch</code>, I get:<br />
<img src="/assets/uploads/files/1774558369980-26fa1cbd-7704-403e-8008-a44027f10050-image.png" alt="26fa1cbd-7704-403e-8008-a44027f10050-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">The changes I made: I fixed the variable/function naming; I updated the window/button strings per german.xml localization file, and I added a wait-loop so if it takes a second or two for the FIND dialog to appear, it will try again rather than give up.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105064</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105064</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 26 Mar 2026 20:54:23 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 20:28:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/native2904" aria-label="Profile: Native2904">@<bdi>Native2904</bdi></a> said in <a href="/post/105062">How can I pass a search term to Notepad++ via command?</a>:</p>
<blockquote>
<p dir="auto">Sorry, but in the GIF, Notepad** is already set to English; it was actually running in German until now.</p>
</blockquote>
<p dir="auto">Most likely, you’re just missing the &amp; to indicate the underlines.</p>
<p dir="auto">But assuming it’s the default German localization, I should be able to figure out what needs to be done, and post the edited version of the script.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105063</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105063</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 26 Mar 2026 20:28:48 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 20:25:10 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, but in the GIF, Notepad** is already set to English; it was actually running in German until now.</p>
<p dir="auto">I first need to get used to the editor’s rules as a new user.<br />
I can no longer edit my first reply with the debug log.<br />
I would like to correct myself: it’s only that one entry I changed.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105062</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105062</guid><dc:creator><![CDATA[Native2904]]></dc:creator><pubDate>Thu, 26 Mar 2026 20:25:10 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 20:12:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a><br />
I only modified her script in such a way that I changed all the names that were different according to the pattern:</p>
<pre><code>hFindBtn = FindWindowEx(hFindWnd, 0, "Button", None)
</code></pre>
<p dir="auto">Debug Info</p>
<pre><code>Notepad++ v8.9.3   (64-bit)
Build time: Mar 20 2026 - 00:44:25
Scintilla/Lexilla included: 5.6.0/5.4.7
Boost Regex included: 1_90
pugixml included: 1.15
nlohmann JSON included: 3.12.0
Path: C:\tcmd\Tools\Notepad++\notepad++.exe
Command Line: C:\tcmd\wincmd.ini -pluginMessage="PythonScriptCommandlineSearch=UseLongNames"
Admin mode: OFF
Local Conf mode: ON
Cloud Config: OFF
WinGUp: present
disableNppAutoUpdate.xml: present
Periodic Backup: ON
Placeholders: OFF
Scintilla Rendering Mode: SC_TECHNOLOGY_DIRECTWRITE (1)
Multi-instance Mode: monoInst
asNotepad: OFF
File Status Auto-Detection: cdEnabledNew (for current file/tab only)
Dark Mode: OFF
Display Info:
    primary monitor: 1920x1080, scaling 125%
    visible monitors count: 1
    installed Display Class adapters: 
        0001: Description - Intel(R) HD Graphics 520
        0001: DriverVersion - 31.0.101.2111
OS Name: Windows 11 Pro (64-bit)
OS Version: 24H2
OS Build: 26100.8037
Current ANSI codepage: 1252
Plugins: 
    ComparePlugin (2.0.2)
    DSpellCheck (1.5)
    Explorer (1.9.9)
    HTMLTag (1.5.2)
    JSMinNPP (1.2503)
    LanguageHelp (1.7.5)
    Linter (0.1)
    MarkdownViewerPlusPlus (0.8.2)
    mimeTools (3.1)
    NppConverter (4.7)
    NppExport (0.4)
    NppJavaPlugin (0.4.1)
    NPPJSONViewer (2.1.1)
    PreviewHTML (1.3.3.2)
    PythonScript (2.1)
    Remove Duplicate Lines (1.3)

</code></pre>
<p dir="auto"><a href="https://imgur.com/snfnGgI" rel="nofollow ugc">Gif_from_action_on_Screen_hosted_on_imgur</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/105061</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105061</guid><dc:creator><![CDATA[Native2904]]></dc:creator><pubDate>Thu, 26 Mar 2026 20:12:37 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 19:16:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/105059">How can I pass a search term to Notepad++ via command?</a>:</p>
<blockquote>
<p dir="auto">Saying “…my script will likely not work for you” seems rather dead-endish…</p>
</blockquote>
<p dir="auto">You’re right.  I should have said, “my script will likely not work for you <em>as is</em>” or “… without edits”.</p>
<p dir="auto">Putting in the exact text of that button is what’s essential for <a class="plugin-mentions-user plugin-mentions-a" href="/user/native2904" aria-label="Profile: Native2904">@<bdi>Native2904</bdi></a> … but if it’s got an underlined character, it needs to be remembered to put the &amp; before that characater in the string.</p>
<p dir="auto">So yes, <a class="plugin-mentions-user plugin-mentions-a" href="/user/native2904" aria-label="Profile: Native2904">@<bdi>Native2904</bdi></a>, if you can put in the text of your Find Next button, and it makes it work, great.  If not, take a screenshot of the Find dialog, and paste it in your reply.  (Also grab <strong>?</strong>-menu’s <strong>Debug Info</strong>)</p>
<p dir="auto"><em>(this is why I’ve mostly stopped doing PythonScript solutions for people… the ultra-slow back-and-forth makes it hard to get things working for them)</em></p>
]]></description><link>https://community.notepad-plus-plus.org/post/105060</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105060</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 26 Mar 2026 19:16:37 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 18:57:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said:</p>
<blockquote>
<p dir="auto">So if there’s anything different from a default setup, my script will likely not work for you.</p>
</blockquote>
<p dir="auto">But surely it isn’t difficult for <a class="plugin-mentions-user plugin-mentions-a" href="/user/native2904" aria-label="Profile: Native2904">@<bdi>Native2904</bdi></a> to edit any necessary text string content in the script, even if “not a programmer”.</p>
<p dir="auto">Saying “…my script will likely not work for you” seems rather dead-endish…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105059</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105059</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 26 Mar 2026 18:57:19 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 18:43:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/native2904" aria-label="Profile: Native2904">@<bdi>Native2904</bdi></a> m</p>
<p dir="auto">For me, it clicks the Find Next.  It worked with 100% of my tests.  Are you using English localization (so the button is literally <code>Find Next</code>) or are you in a different localization?</p>
<p dir="auto">And do you have the single button, like<br />
<img src="/assets/uploads/files/1774550540753-581fa425-8107-4a36-94f8-3e46f8037621-image.png" alt="581fa425-8107-4a36-94f8-3e46f8037621-image.png" class=" img-fluid img-markdown" /><br />
or the two buttons with arrows?<br />
<img src="/assets/uploads/files/1774550558768-f99f8660-677f-47da-83a5-2793aeea3154-image.png" alt="f99f8660-677f-47da-83a5-2793aeea3154-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Because it’s looking for exact button text when trying to figure out what to click; if it cannot find a button called <code>Find Next</code>, then it won’t be able to press it.  So if there’s anything different from a default setup, my script will likely not work for you.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105058</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105058</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 26 Mar 2026 18:43:55 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Thu, 26 Mar 2026 18:21:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a><br />
Thank you very much for taking the time, I really appreciate that!</p>
<p dir="auto">I was able to implement everything so far.</p>
<p dir="auto">I wanted to ask whether you wrote the script so that the search is executed automatically (i.e., the “Find next” button is pressed automatically) or if it only fills the search field with the “term”?</p>
<p dir="auto">For me, the term is only inserted, and I have to trigger the search manually (I’m not a programmer – please excuse my lack of scripting knowledge).</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105057</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105057</guid><dc:creator><![CDATA[Native2904]]></dc:creator><pubDate>Thu, 26 Mar 2026 18:21:09 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Wed, 25 Mar 2026 22:11:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/105044">How can I pass a search term to Notepad++ via command?</a>:</p>
<blockquote>
<p dir="auto">commandlineSearch27482</p>
</blockquote>
<p dir="auto">just noticed that this is actually topic/27472, not 27482… but I’m not going to change all my comments and variable names at this point.  Well, maybe the comment with the URL.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105046</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105046</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 25 Mar 2026 22:11:17 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Wed, 25 Mar 2026 22:07:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said:</p>
<blockquote>
<p dir="auto">…so @alankilborn never published a PythonScript solution. Unfortunately, he’s not around as much anymore</p>
</blockquote>
<p dir="auto">I’m definitely “around”, but more of a lurker these days.  :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105045</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105045</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 25 Mar 2026 22:07:32 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Wed, 25 Mar 2026 22:11:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/105042">How can I pass a search term to Notepad++ via command?</a>:</p>
<blockquote>
<p dir="auto">I might be willing to try to convert the <a href="http://VB.net" rel="nofollow ugc">VB.net</a> script into a PythonScript solution</p>
</blockquote>
<p dir="auto">Here’s my first stab.</p>
<p dir="auto">Instructions:</p>
<p dir="auto">{these assume a normal installation of Notepad++, using %AppData%\Notepad++ for user configuration}</p>
<p dir="auto">See <a href="https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript">PythonScript FAQ</a></p>
<ul>
<li>Create <code>%AppData%\Notepad++\plugins\PythonScript\scripts\commandlineSearch27482.py</code>, from the contents below</li>
<li>Check for menu entry <strong>Plugins &gt; Python Script &gt; Scripts &gt; startup (User)</strong>
<ul>
<li>if it is listed, <code>Ctrl+click</code> on it to edit, and add the following to the end:<pre><code>import commandlineSearch27482
</code></pre>
</li>
<li>if it isn’t listed, create <code>%AppData%\Notepad++\plugins\PythonScript\scripts\user.py</code> from the contents below</li>
<li>set <strong>Plugins &gt; Python Script &gt; Configuration…</strong> to <strong>Initialisation: <code>ATSTARTUP</code></strong></li>
<li>exit and restart Notepad++</li>
</ul>
</li>
</ul>
<p dir="auto">After doing that, the script should look for<br />
<code>notepad++ -pluginMessage="PythonScriptCommandlineSearch=term"</code>, and run a search for <code>term</code></p>
<p dir="auto">For example,</p>
<pre><code>notepad++ -pluginMessage="PythonScriptCommandlineSearch=BM_CLICK"
</code></pre>
<p dir="auto">was able to find <code>BM_CLICK</code> instance when <code>commandlineSearch27482.py</code> is in the editor, so I think it works,  (it worked whether N++ was already running, or whether this call was the first launch)</p>
<p dir="auto">Caveat: For now, it won’t work with semicolon <code>;</code> or double-quote <code>"</code> in the search term; if that is needed, I would need to add an escape sequence processing, which would make it more complicated.  But as it is, it should handle &gt;90% of desired standard searches…</p>
<h3><code>commandlineSearch27482.py</code>:</h3>
<pre><code class="language-py"># encoding=utf-8
"""in response to https://community.notepad-plus-plus.org/topic/27472/ 
(fixed URL)

process -pluginMessage="PythonScriptCommandlineSearch=term"

`term` must be a normal search term, not a regular expression; it currently cannot include semicolons `;` or double-quotes `"`
"""
#####   -------
#####   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\commandlineSearch27482.py`, from the contents below
#####   - Check for menu entry **Plugins &gt; Python Script &gt; Scripts &gt; 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 &gt; Python Script &gt; 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 notepad, console, NOTIFICATION, MENUCOMMAND
import ctypes
import sys
import re

import ctypes
from ctypes.wintypes import HWND, UINT, WPARAM, LPARAM, HMODULE, LPCWSTR, LPCSTR, LPVOID

def usePluginMessageString27482(s):
    m = re.search(r'PythonScriptCommandlineSearch=([^;"]+)', s)
    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

    SendMessage = ctypes.windll.user32.SendMessageW
    SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]
    SendMessage.restype  = LPARAM

    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 = FindWindow("#32770", "Find")
    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)

    # set search mode:
    hNormBtn = FindWindowEx(hFindWnd, 0, "Button", "&amp;Normal")
    if hNormBtn:
        SendMessageStr(hNormBtn, BM_CLICK, 0, None)

    # start search
    hFindBtn = FindWindowEx(hFindWnd, 0, "Button", "Find Next")
    #console.write(f"FindWindows: FIND={hFindWnd:08X} ComboBox={hComboBx:08X} FindNext:{hFindBtn:08X}\n")
    if hFindBtn:
        SendMessageStr(hFindBtn, BM_CLICK, 0, None)

    # 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 getStringFromNotification27482(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")
    usePluginMessageString27482(s)

def getStringFromCommandLine27482():
    for token in sys.argv:
        if len(token)&gt;15 and token[0:15]=="-pluginMessage=":
            s = token[15:]
            #console.write(f"TODO: process {token} =&gt; \"{s}\"\n")
            usePluginMessageString27482(s)

notepad.callback(getStringFromNotification27482, [NOTIFICATION.CMDLINEPLUGINMSG])
console.write("Registered getStringFromNotification27482 callback for CMDLINEPLUGINMSG\n")
getStringFromCommandLine27482()
</code></pre>
<h3><code>startup.py</code>: if you need to create it, use the following</h3>
<pre><code>from Npp import *
import sys

console.write("Start of user startup.py\n")

# add scripts folder to the path
#d = notepad.getPluginConfigDir() + r'\PythonScript\Scripts\nppCommunity'
#if not d in sys.path:
#    sys.path.append(d)
# updated to https://community.notepad-plus-plus.org/topic/22299/convenience-technique-when-organizing-pythonscripts-into-folders
import os
for (root, dirs, files) in os.walk(notepad.getPluginConfigDir() + r'\PythonScript\scripts', topdown=False):
    if root not in sys.path:
        sys.path.append(root)

import commandlineSearch27482
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/105044</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105044</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 25 Mar 2026 22:11:45 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Wed, 25 Mar 2026 20:05:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/105042">How can I pass a search term to Notepad++ via command?</a>:</p>
<blockquote>
<p dir="auto">I don’t know of any plugins that have implemented a start-search-from–pluginMessage: it might make sense for the custom-search gurus – I was about to suggest <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: coises">@<bdi>coises</bdi></a>’s Columns++ … but as I was typing this reply, he posted about a new Search++, which is probably a better place for it: he might be willing to add -pluginMessage processing to trigger a search from the command-line.</p>
<p dir="auto">(If <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: Coises">@<bdi>Coises</bdi></a> doesn’t seem interested, I might be willing to try to convert the <a href="http://VB.net" rel="nofollow ugc">VB.net</a> script into a PythonScript solution… But some users have found it hard to get PythonScript solutions working, despite our FAQ which is supposed to help.)</p>
</blockquote>
<p dir="auto">Offhand, it seems like it would make sense. However, my new plugin still has a lot of work to be done to refine its basic features and add major missing ones. This is a good idea; I’m just not likely to get to it anytime soon.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105043</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105043</guid><dc:creator><![CDATA[Coises]]></dc:creator><pubDate>Wed, 25 Mar 2026 20:05:31 GMT</pubDate></item><item><title><![CDATA[Reply to How can I pass a search term to Notepad++ via command? on Wed, 25 Mar 2026 19:54:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/native2904" aria-label="Profile: Native2904">@<bdi>Native2904</bdi></a> ,</p>
<p dir="auto">Notepad++ doesn’t natively have a command-line-based search syntax.  Sorry.</p>
<p dir="auto">It has come up a few times before, like <a href="/topic/20312">“How to start a search automatically”</a> and <a href="/topic/21856">“Find in Files from command line”</a> (warning: toward the end of both of those, the discussion devolves because of a new direction someone took the conversation; focus on the earlier portions of those discussions).</p>
<p dir="auto">Using a script in the PythonScript plugin to process the <code>-pluginMessage</code> <em>could</em> be used for such a thing.  But I don’t know that anyone’s implemented it.  It never made it to a full script in those previous discussions, because @alankilborn offered, but the OP actually made a <code>VB.net</code> script for it <a href="/post/59785">in this post</a>, so @alankilborn never published a PythonScript solution.  Unfortunately, he’s not around as much anymore, but if he didn’t already write it, he’s not likely to.</p>
<p dir="auto">I don’t know of any plugins that have implemented a start-search-from-<code>-pluginMessage</code>: it might make sense for the custom-search gurus – I was about to suggest <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: coises">@<bdi>coises</bdi></a>’s Columns++ … but as I was typing this reply, he posted about a new <a href="/topic/27473">Search++</a>, which is probably a better place for it: he might be willing to add <code>-pluginMessage</code> processing to trigger a search from the command-line.</p>
<p dir="auto">(If <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: Coises">@<bdi>Coises</bdi></a> doesn’t seem interested, I might be willing to try to convert the <code>VB.net</code> script into a PythonScript solution… But some users have found it hard to get PythonScript solutions working, despite our FAQ which is supposed to help.)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/105042</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/105042</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 25 Mar 2026 19:54:54 GMT</pubDate></item></channel></rss>