Want to change the google search to customer search.

  • I have went inside %appdata%\Notepad++ and modified shortcuts.xlm and changed the search string that controls google.

    This is the default string.
    <Command name=“Google Search” Ctrl=“no” Alt=“yes” Shift=“no” Key=“113”>https://www.google.com/search?q=$(CURRENT_WORD)</Command>

    I replaced it with my custom string and it will take me to the page I have changed it to but it will not pull the highlighted word into the search.

    It works with other search engines. I don’t want to post the search string I am changing it to due to possible security issues.

    Any thoughts?

  • welcome to the notepad++ community, @Cary-Korn

    this is gonna be a bit tricky, because presumably many of us haven’t mastered the art of reading minds yet ;-)

    but with the little information i have, you might have a better chance of solving it yourself, by first trying out your various search urls + strings, by writing them directly into your browser’s address bar, instead of using notepad++ at first.
    example: https://duckduckgo.com/?q=yourkeyword&ia=web

    you will save a lot of time, if you try it out at your browser directly, until you eventually find the correct search syntax for your site.
    once you found the correct way, you can implement it into notepad++.

  • The search string works. The problem seems to be with the syntax I have inside the shortcut.xml file. I am able to change it to other normal search engines but for some reason it will not work with the one I am using. What information could I provide that would help you further?

  • @Cary-Korn

    Hmmm…how about providing a randomized list of all the characters in your search string? This would protect privacy and also maybe call out any oddball characters that could be screwing this up? Maybe…

  • @Cary-Korn
    if you can’t provide the search engine setup you defined it is hard to tell what might
    be the reason why it doesn’t work.
    Most of the time copying what you’ve typed in the browser and replacing the word you have
    searched for with the variable $(CURRENT_WORD) works.
    Could it be that you have to escape certain special chars like &quot; etc …

  • https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&sen=a0T&sen=0WO&sen=a0W&sen=ka&sen=00O&sen=00P&sen=a0b&sen=00T&sen=015&sen=00U&sen=a4j&sen=a1F&sen=a0h&sen=00a&sen=a1S&sen=0F9&sen=a1U&sen=08p&sen=a1X&sen=a3c&sen=02s&sen=001&sen=068&sen=003&sen=500&sen=005&sen=501&sen=006&sen=a6M&sen=a0L&sen=a0M&str=Test )

    This is the search string with a generic url. I have been able to make this work as a custom search engine in chrome. By replacing the search term test. I got this string by searching in the site and pulling it from that. Have been replacing the =test with the current word function in the file.

  • @Cary-Korn,

    My shortcuts.xml has a few customized searches, all of which work for me:

        <Command name="Get perldoc info" Ctrl="no" Alt="yes" Shift="no" Key="112">http://perldoc.perl.org/search.html?q=$(CURRENT_WORD)</Command>
        <Command name="Get perl module info" Ctrl="no" Alt="yes" Shift="no" Key="113">https://metacpan.org/search?q=$(CURRENT_WORD)</Command>
        <Command name="Wikipedia Search" Ctrl="no" Alt="yes" Shift="no" Key="114">https://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD)</Command>

    If I duplicate your search URL, replacing the Test with $(CURRENT_WORD):

        <Command name="CaryKornSearch" Ctrl="no" Alt="yes" Shift="no" Key="0">https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&sen=a0T&sen=0WO&sen=a0W&sen=ka&sen=00O&sen=00P&sen=a0b&sen=00T&sen=015&sen=00U&sen=a4j&sen=a1F&sen=a0h&sen=00a&sen=a1S&sen=0F9&sen=a1U&sen=08p&sen=a1X&sen=a3c&sen=02s&sen=001&sen=068&sen=003&sen=500&sen=005&sen=501&sen=006&sen=a6M&sen=a0L&sen=a0M&str=$(CURRENT_WORD)</Command>

    and save that in my shortcuts.xml, then exit/reload, highlight a word, and try to go to that URL, it tries to actually go to “https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&sen=a0T&sen=0WO&sen=a0W&sen=ka&sen=00O&sen=00P&sen=a0b&sen=00T&sen=015&sen=00U&sen=a4j&sen=a1F&sen=a0h&sen=00a&sen=a1S&sen=0F9&sen=a1U&sen=08p&sen=a1X&sen=a3c&sen=02s&sen=001&sen=06” – it looks like it’s hitting a URL-length limit.

    If I shorten that to:

        <Command name="CaryKornShortURL" Ctrl="no" Alt="yes" Shift="no" Key="0">https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&str=$(CURRENT_WORD)</Command>

    and have the word NPP_FULL_FILE_PATH highlighted after my reload, then Run > CaryKornShortURL takes me to https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&str=NPP_FULL_FILE_PATH, which is what I’d expect. (Admittedly, the test.my.testforce.com is a dummy-domain, so I get an error result, but that’s the URL that’s tried to go to)

    Do you really need so many of the same sen=... keyword, with so many values? Often times, search engines add extra keyword/value pairs after doing a redirection, but you don’t really need to include all of those in a manual search. Would the shortened version I show take you to the right search results? If not, can you come up with a minimum-length URL that will get you to the right search results? You might just try moving the &str=... term earlier in the search URL, like

        <Command name="CaryKornReorderedURL" Ctrl="no" Alt="yes" Shift="no" Key="0">https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&str=$(CURRENT_WORD)&sen=a0T&sen=0WO&sen=a0W&sen=ka&sen=00O&sen=00P&sen=a0b&sen=00T&sen=015&sen=00U&sen=a4j&sen=a1F&sen=a0h&sen=00a&sen=a1S&sen=0F9&sen=a1U&sen=08p&sen=a1X&sen=a3c&sen=02s&sen=001&sen=068&sen=003&sen=500&sen=005&sen=501&sen=006&sen=a6M&sen=a0L&sen=a0M</Command>

  • @Cary-Korn

    a bet (0,01€) :-D
    you haven’t replaced & with &amp; in the shortcuts.xml

  • @Ekopalypse

    I second that…32 times…or if I’m “2nding” it, should that be 16x ??

  • @Ekopalypse said:

    you haven’t replaced & with & in the shortcuts.xml

    A seemingly good bet, but when I converted the longest version I showed above to use &amp; instead of &:

        <Command name="CaryKornSearch" Ctrl="no" Alt="yes" Shift="no" Key="0">https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&amp;sen=a0T&amp;sen=0WO&amp;sen=a0W&amp;sen=ka&amp;sen=00O&amp;sen=00P&amp;sen=a0b&amp;sen=00T&amp;sen=015&amp;sen=00U&amp;sen=a4j&amp;sen=a1F&amp;sen=a0h&amp;sen=00a&amp;sen=a1S&amp;sen=0F9&amp;sen=a1U&amp;sen=08p&amp;sen=a1X&amp;sen=a3c&amp;sen=02s&amp;sen=001&amp;sen=068&amp;sen=003&amp;sen=500&amp;sen=005&amp;sen=501&amp;sen=006&amp;sen=a6M&amp;sen=a0L&amp;sen=a0M&amp;str=$(CURRENT_WORD)</Command>

    it still resolves to the URL https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&sen=a0T&sen=0WO&sen=a0W&sen=ka&sen=00O&sen=00P&sen=a0b&sen=00T&sen=015&sen=00U&sen=a4j&sen=a1F&sen=a0h&sen=00a&sen=a1S&sen=0F9&sen=a1U&sen=08p&sen=a1X&sen=a3c&sen=02s&sen=001&sen=06 – so I think it’s hitting a character limit somewhere – and that somewhere is after it’s parsed the XML and converted it into normal & internally, because it stopped in the same place it did in my example above.

    If I use

        <Command name="SuperLongSearch" Ctrl="no" Alt="yes" Shift="no" Key="0">https://dummy.example/?search=$(CURRENT_WORD);long=123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789j123456789k123456789l123456789m123456789n123456789o123456789p123456789q123456789r123456789s123456789t123456789u123456789v123456789w123456789z123456789w123456789z</Command>

    so the URL is 296 characters plus the search term (260 for the 10*26, plus 36 fixed, plus however long $(CURRENT_WORD) resolves to, and highlight the word WORD, it tries to go to the URL https://dummy.example/?search=WORD;long=123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789j123456789k123456789l123456789m123456789n123456789o123456789p123456789q123456789r123456789s123456789t12345678 – so it stripped 52 characters from the URL I would expect.

    With SUPERCALIFRAGILISTICEXPIALIDOCIOUS highlighted, it went to https://dummy.example/?search=SUPERCALIFRAGILISTICEXPIALIDOCIOUS;long=123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789j123456789k123456789l123456789m123456789n123456789o123456789p123456789q123456789r123456789, so it stripped 61 characters… which is odd, since SUPERCALIFRAGILISTICEXPIALIDOCIOUS is more than 9 characters more than WORD.

    (edits clarified a couple things)

  • @PeterJones
    You hit my language barrier :-)
    I don’t get what you are saying.
    As far as I can understand, you think that there is a limit how long a command can be, right?
    A brief look in the source code didn’t reveal this limit but might be somewhere else set and
    because you tested it and I’m certain you did it correctly I assume it is set somewhere else indeed.
    What confuses me is our conversation about escaping the ampersand.
    From xml point of view there is a need to escape it, don’t you agree?

  • @Ekopalypse ,

    Sorry, your English here is so fluent, I forget it’s not your native language.

    Regarding escaping ampersands in XML: yes, technically, the ampersands should be escaped (made into &amp; entities) in the XML. However, many XML parsers realize that it’s not an entity once they get to the = without having come across a valid entity name, and so decide that the &sel= was meant as literal text rather than as an attempt at a named entity. My experiment above, where the URL was the same (whether the &sel= were raw or &amp;sel=) seems to indicate that the XML-parser that Notepad++ is using implements the fallback condition rather than complaining that it cannot parse the XML.

    Regarding the length: Yes, I think there’s a limit to how long the command can be. I’m not sure how else to interpret the experiments I did with dummy.example, which didn’t use any ampersands, but show the URL getting truncated by the time it reaches the browser. I don’t know whether the limit is

    • when reading the XML file – I don’t think so, because the truncated length seemed to be the same whether I used raw & or entity &amp; in the XML file
    • sometime after converting the entities into plain text inside Notepad++ – I think this is more likely, though where that “somewhere” is would be more complicated
    • sometime between when Notepad++ sends the URL to the browser and the browser receives it – this is also possible
    • windows is truncating it in the between-time
    • the browser (in my experiment, chrome) has a limit as to how many characters it accepts from whatever mechanism it receives the URL from windows

    I may have to look into the code, and/or try some more experiments, to try to pin down where the problem lies.

  • @PeterJones

    fluent English !? :-D - thanks to deepl

    Ok - finally, I guess, I’ve understood.
    The limit you’ve discovered is near to 260 which is a known limit for path length, as far as I remember.
    I read that in Win10 this limit has been eliminated but if it is set in source …
    Thx for the hint about the xml parser, I wasn’t aware that this is even possible.
    I always thought escaping these 5 special chars is a must have.
    Learned something new :-)

  • Google translate usually generates passable English, but I thought I would be able to recognize text that had gone thru translator as compared to even a non-native trying to translate his language into English. I guess deepl is pretty convincing. :-)

    Don’t let my laziness of letting the xml-parser handle my malformed XML corrupt you into to taking shortcuts. I don’t use XML for more than editing config files here and elsewhere, and such applications often follow the adage “Be conservative in what you send, be liberal in what you accept” (Postel’s Law). If I were writing XML for a living, I’d be much more strict in any XML example I gave. It’s best to always use entities for those 5 characters in XML when you are writing XML.

  • To be honest, I don’t know if I’m using it correctly at all because I let it translate from English into German
    and I’m changing it until the German translation makes sense to me.
    But it looks like it generates a much better English translation this way than the other way around.
    Which, of course, could mean, that I constantly produce English text with German grammar :-)

    With google translate I wasn’t able to get a proper result using it this way
    but have to admit that I haven’t used it for quite some time now.
    And if used in the normal way, it always made me feel that there is something wrong.
    But who knows, maybe it is much better nowadays.

  • Back on topic:

    I was curious, so I followed these directions to create a fake URL protocol/scheme (“alert:xxx”), but I just passed it to cmd /c "echo %1 && pause". After refreshing my login, I then updated shortcuts.xml to add an Run > alert using Alt+F5:

        <Command name="alert" Ctrl="no" Alt="yes" Shift="no" Key="116">alert:$(CURRENT_WORD)</Command>

    When running that, with the text 123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x selected, it stops at 259 characters, including the alert: protocol prefix. I hadn’t realized that the 260-character limitation would apply to commands as well as filenames.

    I haven’t found anywhere where there’s a 260+/-1 hardcoded in Notepad++ source code that would influence this (one of the Lexers apparently hardcodes a 260-character limit in one of its buffers, but none others that appeared to deal with strings), so maybe it’s really in the libraries that NPP chose to handoff to windows, or something.

    Adding a command-based rather than URL-based:

        <Command name="alertcmd" Ctrl="no" Alt="yes" Shift="no" Key="118">cmd /c "echo $(CURRENT_WORD) && pause"</Command>

    I successfully passed that up to 2047 characters in $(CURRENT_WORD).

    With that in mind, and the launch in browser syntax, I created

         <Command name="cmdurl" Ctrl="no" Alt="yes" Shift="no" Key="119">chrome file:$(CURRENT_WORD)"</Command>

    which launches chrome with the given file: URL. I was able to pass it 2047 characters no problem

    So edit cmdurl to the @Cary-Korn’s original long-URL example, with proper &amp;-entities:

         <Command name="cmdurl" Ctrl="no" Alt="yes" Shift="no" Key="119">chrome https://test.my.testforce.com/_ui/search/ui/UnifiedSearchResults?searchType=2&amp;sen=a0T&amp;sen=0WO&amp;sen=a0W&amp;sen=ka&amp;sen=00O&amp;sen=00P&amp;sen=a0b&amp;sen=00T&amp;sen=015&amp;sen=00U&amp;sen=a4j&amp;sen=a1F&amp;sen=a0h&amp;sen=00a&amp;sen=a1S&amp;sen=0F9&amp;sen=a1U&amp;sen=08p&amp;sen=a1X&amp;sen=a3c&amp;sen=02s&amp;sen=001&amp;sen=068&amp;sen=003&amp;sen=500&amp;sen=005&amp;sen=501&amp;sen=006&amp;sen=a6M&amp;sen=a0L&amp;sen=a0M&amp;str=$(CURRENT_WORD)</Command>

    When I did that, it hit a limit of the ~260 characters again. (Though, this time, instead of clipping, it wrapped around and started the URL over for a few more characters; it was weird). I think that the way that command-line arguments are being sent to ShellExecute, and/or how ShellExecute is handling them, is limiting the argument to a command to be ~260 characters.

  • So, the end-result is: @Cary-Korn, try to pare down your URL to be able to be significantly less than 260 characters without the $(CURRENT_WORD) value, so that it will stay <260-characters with that value embedded in the URL. Or use some sort of URL-shrinking service that allows passing parameters, so you could use https://fake.url/shortener?str=$(CURRENT_WORD), where all the other parameters are internal to the url-shortener service.

  • @PeterJones

    I guess you are on the right track. I assume the underlying create process is the culprit.
    As stated on msdn

    The maximum length of this string is 32,768 characters, including the Unicode terminating null character.
    If lpApplicationName is NULL, the module name portion of lpCommandLine is limited to MAX_PATH characters.

  • Thanks for all the help. I have played with the url trying to shorten it but it seems to glitch the search. It keeps asking for the search to be more than 2 characters long. The url shorten might work just not sure of any service that can parse the search term to make it work. This might be something that is just not possible with this site.

  • @Cary-Korn

    just a thought, to get the line shorter within notepad++:

    can you perform a search from a test.cmd batch file ?
    if yes, you can try to call your_path_to\test.cmd $(CURRENT_WORD) or your_path_to\test.cmd "$(CURRENT_WORD)" inside shortcuts.xml, to keep the notepad++ executable line as short as possible.

    shortcuts.xml example:

    <Command name="test" Ctrl="no" Alt="no" Shift="no" Key="0">C:\Users\user\test.cmd $(CURRENT_WORD)</Command>

    inside the batch file $(CURRENT_WORD) will be reflected as %1

Log in to reply