How to insert text at the end of every url (via a macro)?



  • First I beg pardon for my poor english.

    In the ‘shortcuts.xml’ I have some macros; how can I modify them directly (without running NPP) to insert text at the end of an URL?

    Macro code (one of the macros):

        <Macro name="youtube --&gt; youtube-dl" Ctrl="yes" Alt="yes" Shift="no" Key="67">
            <Action type="0" message="2013" wParam="0" lParam="0" sParam="" />
            <Action type="2" message="0" wParam="42007" lParam="0" sParam="" />
            <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
            <Action type="3" message="1601" wParam="0" lParam="0" sParam="https://www.youtube.com/watch?v=" />
            <Action type="3" message="1625" wParam="0" lParam="0" sParam="" />
            <Action type="3" message="1602" wParam="0" lParam="0" sParam='youtube-dl --ffmpeg-location c:\ffmpeg\ --download-archive ..\archive.txt  -i --geo-bypass -o &quot;%%(title)s.%%(ext)s&quot; https://youtu.be/' />
            <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />
            <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
        </Macro>
    

    Which line (action, params, …) will I have to insert, to make it work?

    Kind regards

    Kurt (Austria, not Australia)



  • @khk-khk said in How to insert text at the end of every url (via a macro)?:

    how can I modify them directly (without running NPP)

    Your english is quite good so no apology needed. As for editing macros directly can I get you to read (from the NPP manual) this info:
    https://npp-user-manual.org/docs/config-files/#macros

    I will say first off that editing directly isn’t for the faint of heart. The code isn’t easy to read. I tried to understand what your’s is doing but I gave up very quickly.

    It would appear you are looking for some text “…youtube.com…” and then later in the macro there is some other text but I cannot identify the codes so don’t know if it’s a replacement or what.

    As a suggestion make up a macro that looks for some text, then inserts (as you want) more text "at the end of a URL/line. This can be dummy data, just so you can see the macro code once it is saved. Then from knowing what that macro does you should be able to easily replace the “find what” text and the “replace with” text.

    Good luck
    Terry



  • Dear Terry (or all the others),

    seems to be a good idea, but doesn’t work.

    I made a macro only for appending text (see following code), copied it to my original macro, but it ended (instead of adding the text ’ >> …\log.txt’ to every line in the file) with a single line containing ’ >> …\log.txt’; so what’s wrong?

        <Macro name="test" Ctrl="yes" Alt="yes" Shift="yes" Key="49">
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&gt;" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&gt;" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="." />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="." />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="\" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="l" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="o" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="g" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="." />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="t" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="x" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="t" />
            <Action type="0" message="2300" wParam="0" lParam="0" sParam="" />
        </Macro>
    

    Kind regards

    Kurt (Austria)



  • @khk-khk

    2170 is the scintilla code for replace selected text, so if you have selected the text prior to run the macro it got replaced.

    In your case I would have assume you do something like

    <Action type="0" message="2314" wParam="0" lParam="0" sParam="" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" &gt;&gt; ..\log.txt" />
    <Action type="0" message="2300" wParam="0" lParam="0" sParam="" />
    

    and then run your macro multiple times.



  • Dear Ekopalypse,

    your lines worked for the first line in the file, but there are a lot of lines to change, so it’s a heavy work to run it multiple times; isn’t it possible to do it in my single macro I posted 9 hours ago?

    Kind regards

    Kurt (Austria)



  • @khk-khk ,

    Your second script, with the 2170 (which is ReplaceSel) and 2300 (which is LineDown, effectively replaces the selection with >> ..\log.txt: if you have nothing selected, it will start at the cursor and type those characters; if you have the whole document selected, it will replace the entire document with a single copy of that text. After it’s done with the replace commands, it is using the LineDown command to move down one line. Then the macro stops. If you want the macro to do more than that, you have to tell it to do more than that. And no, the Macro language doesn’t have loops or counters, so you cannot just repeat-until-end-of-file with that macro.

    That said, the Notepad++ search-and-replace functions can be recorded in macros. With regex-based search-and-replace, and the Replace All function, you can easily accomplish your goal:

    • Macro > Start Recording
    • Search > Replace
      • FIND = (?-s)(?<=.)$ – make sure dot doesn’t match newline; make sure there’s at least one character in the line (I assumed you didn’t want to add the text to an empty line); match the end of the line
      • REPLACE = >> ..\\log.txt (there is a space on each side of the >>
        9b32cb03-1306-4bcb-9cf4-65827b925302-image.png
      • REPLACE ALL
    • Macro > Stop Recording
    • Macro > Save Current Recorded Macro

    After exiting Notepad++, shortcuts.xml should contain a macro similar to:

            <Macro name="ForumPost19765" Ctrl="no" Alt="no" Shift="no" Key="0">
                <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)(?&lt;=.)$" />
                <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                <Action type="3" message="1602" wParam="0" lParam="0" sParam=" &gt;&gt; ..\\log.txt" />
                <Action type="3" message="1702" wParam="0" lParam="770" sParam="" />
                <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
            </Macro>
    

    There is a whole section of details on search-and-replace macros in the official docs here: https://npp-user-manual.org/docs/searching/#searching-actions-when-recorded-as-macros – that will explain the 1700, 1601, 1625, 1602, 1702, 1701 sequence (including that the message=“1701” with lParam=“1609” means “Replace All”).



  • Dear Peter,

    this was the information I needed; now the macro works fine.

    Lots of thanks to all who (tried) to help me.

    Kr

    Kurt


Log in to reply