Community
    • Login

    HELP: Having trouble with Macros in v8.5.3 or later

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    28 Posts 9 Posters 5.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • datatraveller1D
      datatraveller1 @PeterJones
      last edited by

      @PeterJones I have a macro which inserts a new line:
      <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
      <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />

      &#x000D;&#x000A; gets inserted literally instead of a new line (CR/LF) with version v8.5.3. I tried to use “\n” instead but this gets inserted literally too. What am I doing wrong?

      datatraveller1D 1 Reply Last reply Reply Quote 0
      • datatraveller1D
        datatraveller1 @datatraveller1
        last edited by

        So I have found the solution (thanks to @PeterJones) in the FAQ:
        Find what: &#x000D; Replace With: \x{000D}
        Find what: &#x000A; Replace With: \x{000A}
        with Search mode set to Regular Expression and run Replace All.

        1 Reply Last reply Reply Quote 1
        • guy038G
          guy038
          last edited by guy038

          Hello, @datatraveller1, @peterjones and All,

          @datatraveller1, I do not think that your macro really adds a line-break when you use the \x{000D} and \x{000A} syntax in the <Macros> node of your shortcut.xml file, in N++ v8.5.3

          Personally, adding the following section, in my portable N++ v5.8.3 installation :

                  <Macro name="ABC + Line-Break" Ctrl="no" Alt="no" Shift="no" Key="0">
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="A" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="B" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000D}" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000a}" />
                  </Macro>
          

          Results, when running this macro in a new tab, by the insertion of the literal text ABC\x{000D}\x{000A}


          Whereas, selecting the string, between the double-quotes of the sParam attribute, and :

          • Hitting the ALT key and, pressing simultaneously the 0, 1 and 3 keys, on the numeric keypad, does insert a true CR character

          • Hitting the ALT key and, pressing simultaneously the 0, 1 and 0 keys, on the numeric keypad, does insert a true LF character

          In the last two lines Action of the macro and gives this text :

                  <Macro name="ABC + Line-Break" Ctrl="no" Alt="no" Shift="no" Key="0">
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="A" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="B" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="
          " />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="
          " />
                  </Macro>
          

          IMPORTANT : If you paste this text in a new tab, don’t forget to change the line-break of two last lines with CR and LF, instead of keeping two CRLF lines !

          Just select the two chars CRLF of the last two lines and use the ALT + numeric keypad method to change the first line-break as CR and the second one as LF. Delete any non-intentional leading TAB chars, too.


          Running this last version of the macro does write the ABC string followed with a Windows line-break CRLF ;-))

          My debug info :

          Notepad++ v8.5.3   (64-bit)
          Build time : May 15 2023 - 06:09:36
          Path : E:\853_x64\notepad++.exe
          Command Line : 
          Admin mode : OFF
          Local Conf mode : ON
          Cloud Config : OFF
          OS Name : Windows 10 Pro (64-bit)
          OS Version : 22H2
          OS Build : 19045.2965
          Current ANSI codepage : 1252
          Plugins : 
              mimeTools (2.9)
              NppConverter (4.5)
              NppExport (0.4)
          

          Best Regards,

          guy038

          datatraveller1D PeterJonesP 2 Replies Last reply Reply Quote 1
          • datatraveller1D
            datatraveller1 @guy038
            last edited by

            Hi @guy038 thank you, CR and LF got inserted as real line breaks with the FAQ solution:

            80ce0429-952a-433f-a7dc-4f822701271c-image.png

            1 Reply Last reply Reply Quote 1
            • wonkawillyW
              wonkawilly
              last edited by

              I am having that kind of trubble my self too. I am getting errors of encoding in simple strings with accents for example with the use of the following caracters: à ù ò.
              Please have a look at the following picture:

              88ecb38d-989a-48bc-8f71-29247bc804ad-image.png

              Maybe the new implementation is not yet complete.

              Thank for reading.

              1 Reply Last reply Reply Quote 0
              • guy038G
                guy038
                last edited by guy038

                Hello, @wonkawilly and All,

                Finally, @wonkawilly, here is the right way to enter any character according to the new behaviour of macros, in N++ v.8.5.3!


                • Open your active shortcuts.xml file in Notepad++

                • Insert the empty template, below, at the end of the Macros section, right before </Macros>, in your shortcuts.xml file :

                        <Macro name="Test" Ctrl="no" Alt="no" Shift="no" Key="0">
                            <Action type="1" message="2170" wParam="0" lParam="0" sParam="" />
                        </Macro>
                
                • Duplicate the line <Action type="1" message="2170" wParam="0" lParam="0" sParam="" />, as many times as the number of chars to be inserted, incuding a possible line-break, with the Ctrl + D shortcut

                => In your exemple, we’ll add four lines

                        <Macro name="Test" Ctrl="no" Alt="no" Shift="no" Key="0">
                            <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="" />
                        </Macro>~~~
                
                • Put your caret/cursor between the two double-quotes of each sParam attribute

                • Open the Edit > Character Panel menu option

                • Double-click on the characters to insert, located under the ‘Character’ column of the Character Panel. Thus, for the line-break chars, just double-click on CR, then LF !

                => We get this functional macro :

                        <Macro name="Test" Ctrl="no" Alt="no" Shift="no" Key="0">
                            <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="
                " />
                        </Macro>
                
                • Save your shortcuts.xml file

                • Close and restart N++

                Enjoy your Test macro !

                Best Regards,

                guy038

                wonkawillyW 1 Reply Last reply Reply Quote 0
                • wonkawillyW
                  wonkawilly @guy038
                  last edited by

                  @guy038 said in HELP: Having trouble with Macros in v8.5.3 or later:

                  here is the right way to enter any character according to the new behaviour of macros, in N++ v.8.5.3!

                  The right way became a little bit more cumbersome than before… I rather like to write whole string with the keyboard or even better by voice.

                  I have to say that if there is a thing that I really hate about N++ since the first usage is the macro system. I would like to see it replaced with a better language for example js, py, cs or else, keeping the capability to record commands executed into N++ and adding the possibility to modify a macro written into a real and serious programming language that is easily human readable and modifiable than the macro system actually implemented that is really ugly.

                  datatraveller1D 1 Reply Last reply Reply Quote 0
                  • datatraveller1D
                    datatraveller1 @wonkawilly
                    last edited by datatraveller1

                    @wonkawilly As far as I have understood @guy038 and the FAQ, you simply have to replace the old values UTF-8 encoded literally with è, à etc.

                    I’m not sure if something like Python would work for the macro system but I partly agree that it is a bit ugly sometimes - In my case I don’t like that real line breaks get inserted into shortcuts.xml.

                    wonkawillyW 1 Reply Last reply Reply Quote 3
                    • guy038G
                      guy038
                      last edited by guy038

                      Hi, @wonkawilly, @datatraveller1 and all,

                      But, of course, if a character is available on your keyboard, you may, as well, just type in this character !!

                      It’s only for special chars as line-break chars and some others that you need the help of the Character Panel

                      For instance, for the line-break chars, just use the method, described in my post to @datatraveller1, using ALT + 013 and ALT + 010, on the numeric keypad

                      BR

                      guy038

                      P.S :

                      @datatraveller1, The best when creating macros is to open the Character Panel, first and :

                      • Double-click on [ CR and ] LF, each time you want to insert a line-break in a macro

                      • Double-click on any character when this char is not available on your keyboard !

                      1 Reply Last reply Reply Quote 1
                      • Alan KilbornA
                        Alan Kilborn
                        last edited by

                        Certainly copy and paste of a character from another source also works fine as an alternative to using the Character Panel, which has a limited number of possible characters anyway.

                        But, as stated, probably Character Panel is a good choice for carriage-return and line-feed characters.

                        1 Reply Last reply Reply Quote 2
                        • PeterJonesP
                          PeterJones @guy038
                          last edited by PeterJones

                          I was going back through some of the posts here, to see if there are improvements that can be made to the FAQ.

                          @guy038,

                          I do not think that your macro really adds a line-break when you use the \x{000D} and \x{000A} syntax in the <Macros> node of your shortcut.xml file, in N++ v8.5.3

                          I think you misread @datatraveller1: you seemed to asssume he changed to the literal

                          <Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000D}" />
                          <Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000A}" />
                          

                          If that had been the case, it wouldn’t work. But based on the “find what” and “replace with” in the post you replied to, he actually followed the advice found in the FAQ, which is when editing shortcuts.xml to use Notepad++ Replace window to run a regex search-and-replace. Using the “find what” and “replace with” that @datatraveller1 mentioned, and which I suggested in the FAQ, will change the &#x000D; sequence to the actual CR character and &#x000A; with the actual LF character.

                          Later, @guy038 also wrote:

                          Duplicate the line <Action type="1" message="2170" wParam="0" lParam="0" sParam="" />, as many times as the number of chars to be inserted, including a possible line-break, with the Ctrl + D shortcut

                          There’s no need. The macro recorder just puts one character per 2170-message, but that’s not a restriction of the macro playback. If you are editing a macro and want to insert the text èòù[CRLF], the single action

                          <Action type="1" message="2170" wParam="0" lParam="0" sParam="èòù
                          " />
                          

                          will work (assuming the linebreak in the sParam is really a CR and LF)

                          That said, based on what I’ve re-read here, I will suggest the Alt+013 and Alt+010 methods of entering those characters, and using the Character Panel (or Run > Run… > charmap.exe) for entering characters that aren’t on your keyboard.

                          1 Reply Last reply Reply Quote 2
                          • guy038G
                            guy038
                            last edited by guy038

                            Hello, @wonkawilly, @datatraveller1, @alan-kilborn and all,

                            Oh… Of course, I forgot to mention that, in my previous posts, I refered to macros already created by a user with a N++ version prior to v8.5.3 !

                            If, with N++ v.8.5.3, you just create a new macro, containing one or several line-break(s), it’ll be correctly recorded !

                            However, I noticed some oddities when recording these line-breaks !


                            Follow these different actions for testing :

                            • Open N++ v.8.5.3

                            • Open a new tab

                            • If the line-break format of the new tab is not Windows (CR LF), in the status bar, change it with the command Edit > EOL Conversion > Windows (CR LF)

                            • Start recording a macro with the command Macro > Start Recording

                            • In the new tab, just type in the string ABC and hit the Enter key

                            • Then, type in the string DEF and hit , again, the Enter key

                            • Stop recording the current macro with the command Macro > Stop Recording

                            • Click on the the menu option Macro > Save Current Recorded Macro...

                            • Give the name Test_CRLF to this macro

                            • Delete all contents of this new tab with a Ctrl + Z operation

                            • Change the EOL format of the new tab to Unix, with the command Edit > EOL Conversion > Unix (LF)

                            • Start recording a macro with the command Macro > Start Recording

                            • In the new tab, just type in the string GHI and hit the Enter key

                            • Then, type in the string JKL and hit , again, the Enter key

                            • Stop recording the current macro with the command Macro > Stop Recording

                            • Click on the the menu option Macro > Save Current Recorded Macro...

                            • Give the name Test_LF to this macro

                            • Delete all contents of this new tab with a Ctrl + Z operation

                            • Change the EOL format of the new tab to Mac, with the command Edit > EOL Conversion > Macintosh (CR)

                            • Start recording a macro with the command Macro > Start Recording

                            • In the new tab, just type in the string MNO and hit the Enter key

                            • Then, type in the string PQR and hit , again, the Enter key

                            • Stop recording the current macro with the command Macro > Stop Recording

                            • Click on the the menu option Macro > Save Current Recorded Macro...

                            • Give the name Test_CR to this macro

                            • Close N++ v.8.5.3, without saving the new tab

                            • Restart N++ v.8.5.3

                            • Open your active shortcuts.xml file

                            • Note the contents of the three macros Test_CRLF , Test_LF and Test_CR :

                              • In the Test_CRLF macro, the first part of each EOL recording is the CR character ( OK ) but the second part is CRLF and not LF ( ?? )

                              • In the Test_LF macro, the two EOL recording are the CRLF characters and not the LF chars ( ?? )

                              • In the Test_CR macro, the two EOL recording are correctly the CR characters ( OK )

                            I don’t know, if we should trigger an GitHub issue for these oddities ??

                            Best Regards

                            guy038

                            P.S. : I’ve just seen the @peterjones’s post… and will have a look at it !

                            Alan KilbornA 1 Reply Last reply Reply Quote 2
                            • Alan KilbornA
                              Alan Kilborn @guy038
                              last edited by Alan Kilborn

                              @guy038 said in HELP: Having trouble with Macros in v8.5.3 or later:

                              Note the contents of the macros Test_CRLF , Test_LF

                              I can duplicate your poor results with these two. :-(

                              if we should trigger an GitHub issue for these oddities ??

                              Either that, or post about it in the 8.5.3 release thread, HERE.

                              1 Reply Last reply Reply Quote 1
                              • guy038G guy038 referenced this topic on
                              • Massimo PiscopoM
                                Massimo Piscopo @PeterJones
                                last edited by

                                I’ve a similar problem.
                                I’ve created a macro doing a lot of things, included changing “word” into ‘word’ (look for ‘ ’ instead of " ").
                                This worked ok until last update (8.5.3, build May 15 2023 06:07:16).
                                Now the macro (I don’have touched it) change “word” into

                                & # x 2 0 1 8 ; w o r d & # x 2 0 1 8 ;

                                Please ignore spaces: if I don’t insert spaces, this forum convert “& # x 2 0 1 8 ; w o r d & # x 2 0 1 8 ;” into " ‘word’ " and it’s impossible to understand what I mean.
                                I need Notepad++ don’t “convert” the ‘ ’ symbols.

                                I’ve tried to search my macro recorded but I don’t find it in shortcuts.xml. Where I can find it? My macro is called “calcio (prime correzioni)” but in shortcuts.xml I find only “Trim Trailing Space and Save”. BTW the date of shortcuts.xml is from 2021 and maybe my macro was created after.

                                PeterJonesP 1 Reply Last reply Reply Quote 0
                                • guy038G
                                  guy038
                                  last edited by

                                  Hello, @massimo-piscopo and All,

                                  I suppose that you have a standard installation with N++ installer ! Then, you must look for the real location of your shortcuts.xml file !


                                  Follow the steps, below :

                                  • Open your Notepad++ v8.5.3, as usual

                                  • Click on the Windows Logo key and, simultaneously, hit the R key

                                  • In the Execute window, type in Explorer.exe and hit the Enter key

                                  => The File Explorer program should start

                                  • Clic on the ‘STAR’ and type in the string %appdata%\Notepad++

                                  • Valid with the Enter key

                                  => You should normally see a shortcuts.xml file, along with some others files

                                  • Clic on the shortcuts.xml file and drag this file into your notepad++ window

                                  => You should see, in the <Macros> section, your macro named calcio (prime correczioni)

                                  • Now, open the Replace dialog ( Ctrl + H )

                                  • Untick all box options

                                  • SEARCH &#x2018;

                                  • REPLACE \x{2018}

                                  • Check the wrap around option

                                  • Select the Regular expression search mode ( IMPORTANT )

                                  • Click on the Replace All button

                                  • Save the changes of your shortcuts.xml file

                                  • Close Notepad++

                                  • Restart Notepad++

                                  => Your macro should be OK and do what it is designed for :-)

                                  Best Regards,

                                  guy038

                                  1 Reply Last reply Reply Quote 2
                                  • PeterJonesP
                                    PeterJones @Massimo Piscopo
                                    last edited by

                                    @Massimo-Piscopo ,

                                    I don’t find it in shortcuts.xml

                                    It’s there, or your macro doesn’t exist when you exit Notepad++ and restart. Did you look in the right shortcuts.xml?

                                    If you had read the first post in this discussion, you would have seen the we asked you to supply your ?-menu’s Debug Info. Because you chose not to do so, we have to assume the location of your shortcuts.xml is in %AppData%\Notepad++\shortcuts.xml, as @guy038 guessed while I was typing this.

                                    Massimo PiscopoM 1 Reply Last reply Reply Quote 3
                                    • Massimo PiscopoM
                                      Massimo Piscopo @PeterJones
                                      last edited by

                                      @guy038 and @PeterJones THANK YOU SO MUCH, I’ve solved. <3

                                      1 Reply Last reply Reply Quote 1
                                      • wonkawillyW
                                        wonkawilly @datatraveller1
                                        last edited by

                                        @datatraveller1 said in HELP: Having trouble with Macros in v8.5.3 or later:

                                        @wonkawilly As far as I have understood @guy038 and the FAQ, you simply have to replace the old values UTF-8 encoded literally with è, à etc.

                                        I’m not sure if something like Python would work for the macro system but I partly agree that it is a bit ugly sometimes - In my case I don’t like that real line breaks get inserted into shortcuts.xml.

                                        It should be good enough to see it replaced with “\r\n” as in regular expression syntax. Nevertheless, that solution would of course be good just to “survive”, not in the long run, because nevertheless the optimus would be to have a complete new macro system as in LibreOffice, MsOffice and so on. It would be a huge improvement even replacing the current macro system in npp with a new macro system based on AutoIt language and macro recorder.
                                        The current macro system is too cryptic and too limited. Compare this row
                                        <Action type=“1” message=“2170” wParam=“0” lParam=“0” sParam=“è” />
                                        with its equivalent in a simple scripting language in which you can even do loops or if/else and so much more.
                                        IMHO the current macro system in N++ is going old… and really needs retirement, better sooner than later…
                                        Also another ugly thing is that n++ saves new recorded macros only on exit: it would be better to save new created macros on click on the Save Macro button so they could be edited without the need of restarting npp: other ugly and incomprehensible thing.

                                        1 Reply Last reply Reply Quote 1
                                        • Cement KnightC
                                          Cement Knight
                                          last edited by

                                          Moving to the next bookmark does not work inside a macro. No matter where the cursor is, it will always go to a specific bookmark.

                                          Alan KilbornA 1 Reply Last reply Reply Quote 0
                                          • Alan KilbornA
                                            Alan Kilborn @Cement Knight
                                            last edited by

                                            @Cement-Knight said in HELP: Having trouble with Macros in v8.5.3 or later:

                                            Moving to the next bookmark does not work inside a macro. No matter where the cursor is, it will always go to a specific bookmark.

                                            You might want to start a new thread with that, as it is very unrelated to previous conversation in this thread.

                                            PeterJonesP 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors