• Login
Community
  • Login

Adding more steps to an existing Macro

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
12 Posts 4 Posters 2.5k 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.
  • R
    Robert Or Janet Diebel @Terry R
    last edited by Dec 24, 2024, 1:12 PM

    @Terry-R said in Adding more steps to an existing Macro:

    recreating the macro with additional steps,

    Yes, I wish to add more steps to an existing Macro. I am using RegEx’s to alter the content.

    A 1 Reply Last reply Dec 24, 2024, 2:42 PM Reply Quote 0
    • A
      Alan Kilborn @Robert Or Janet Diebel
      last edited by Alan Kilborn Dec 24, 2024, 2:44 PM Dec 24, 2024, 2:42 PM

      @Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:

      I wish to add more steps to an existing Macro

      The presumption here is that you created the macro via macro recording.
      No, there is no way to add to it, via recording.

      I am using RegEx’s to alter the content.

      Another presumption is that you’ve recorded one replacement operation into your macro, and now you want to add more of those.
      If so, then it is fairly easy to “hand-edit” the macro to include more such operations.

      • exit Notepad++ to make sure that it saves its current configuration
      • make a copy of your shortcuts.xml file (in case something bad happens) :-)
      • restart Notepad++
      • edit shortcuts.xml and locate your macro within it
      • note that there are a block of lines in the macro starting with 1700 and ending with 1701
      • copy and paste that block of lines at the end of the macro
      • edit the (copied) lines that contain your search regex text and your replacement text, to conform to the new replacement operation that you want to add
      • save shortcuts.xml
      • restart Notepad++

      For much more detail, see the user manual page for this, HERE .

      R 1 Reply Last reply Dec 24, 2024, 3:33 PM Reply Quote 1
      • R
        Robert Or Janet Diebel @Alan Kilborn
        last edited by PeterJones Dec 24, 2024, 3:53 PM Dec 24, 2024, 3:33 PM

        @Alan-Kilborn
        My shortcuts.xml - I have 2 Macros - ParaTxt2Raw and RegExTest.
        How do I find them?


        <?xml version="1.0" encoding="UTF-8" ?>
        <NotepadPlus>
            <InternalCommands />
            <Macros>
                <Macro name="Trim Trailing Space and Save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
                    <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
                    <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
                </Macro>
            </Macros>
            <UserDefinedCommands>
                <Command name="Get PHP help" Ctrl="no" Alt="yes" Shift="no" Key="112">https://www.php.net/$(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>
                <Command name="Open selected file path in new instance" Ctrl="no" Alt="yes" Shift="no" Key="117">$(NPP_FULL_FILE_PATH) $(CURRENT_WORD) -nosession -multiInst</Command>
            </UserDefinedCommands>
            <PluginCommands />
            <ScintillaKeys />
        </NotepadPlus>
        

        —

        moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

        P 1 Reply Last reply Dec 24, 2024, 3:56 PM Reply Quote 0
        • P
          PeterJones @Robert Or Janet Diebel
          last edited by Dec 24, 2024, 3:56 PM

          @Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:

          How do I find them?

          You probably need to open %AppData%\Notepad++\shortcuts.xml, which is the active copy of that file, not the one in your installation directory (which is the one I guess you opened)

          R 3 Replies Last reply Dec 24, 2024, 4:02 PM Reply Quote 0
          • R
            Robert Or Janet Diebel @PeterJones
            last edited by Dec 24, 2024, 4:02 PM

            @PeterJones said in Adding more steps to an existing Macro:

            %AppData%\Notepad++\shortcuts.xm

            You nailed it, Thanx a bunch

            1 Reply Last reply Reply Quote 0
            • R
              Robert Or Janet Diebel @PeterJones
              last edited by Dec 24, 2024, 6:49 PM

              @PeterJones
              Are comments allowed in shortcuts.xml?

              P A 2 Replies Last reply Dec 24, 2024, 7:04 PM Reply Quote 0
              • P
                PeterJones @Robert Or Janet Diebel
                last edited by Dec 24, 2024, 7:04 PM

                @Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:

                @PeterJones
                Are comments allowed in shortcuts.xml?

                Allowed, yes. Preserved, I don’t think so. If you record a new macro or do anything else in the GUI that affects that file (create a run menu entry, or change shortcut in Shortcut Mapper), I seem to remember that it will rewrite the file without your comments.

                I have sometimes used the string attribute on a command that doesn’t use it to create a pseudo-comment in a macro… You can search the forum for my posts about macros, and can probably find an example with pseudo-comments.

                1 Reply Last reply Reply Quote 0
                • R
                  Robert Or Janet Diebel @PeterJones
                  last edited by Robert Or Janet Diebel Dec 24, 2024, 8:12 PM Dec 24, 2024, 7:07 PM

                  @PeterJones
                  OK NOW. I removed the shortcuts.xml file, Stopped/Started Notepad++. It made a new. I modified and it appears to work.
                  Thanx for all the help. This will be so handy!

                  Sorry for not marking code. I will going forward.
                  I cloned and changed the shortcuts.xml.
                  Than stopped/started Notepad++
                  It does not recognize the new file.
                  After changes to the file, or a new file copied in, the Macros I can see in the file are no longer available.


                  <?xml version="1.0" encoding="UTF-8" ?>
                  <NotepadPlus>
                      <InternalCommands />
                      <Macros>
                          <Macro name="Trim Trailing Space and Save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
                              <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
                              <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
                          </Macro>
                          <Macro name="ParaTxt2Raw2" 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="\\id.*?\\p" />
                              <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                              <Action type="3" message="1602" wParam="0" lParam="0" sParam="\\c 1" />
                              <Action type="3" message="1702" wParam="0" lParam="1794" sParam="" />
                              <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                              <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                              <Action type="3" message="1601" wParam="0" lParam="0" sParam="\\[a-z][\s|\r\n]" />
                              <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                              <Action type="3" message="1602" wParam="0" lParam="0" sParam="" />
                              <Action type="3" message="1702" wParam="0" lParam="1794" sParam="" />
                              <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                              <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                              <Action type="3" message="1601" wParam="0" lParam="0" sParam="\r\n\n" />
                              <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                              <Action type="3" message="1602" wParam="0" lParam="0" sParam="\r\n" />
                              <Action type="3" message="1702" wParam="0" lParam="770" sParam="" />
                              <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                          </Macro>
                      </Macros>
                      <UserDefinedCommands>
                          <Command name="Get PHP help" Ctrl="no" Alt="yes" Shift="no" Key="112">https://www.php.net/$(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>
                          <Command name="Open selected file path in new instance" Ctrl="no" Alt="yes" Shift="no" Key="117">$(NPP_FULL_FILE_PATH) $(CURRENT_WORD) -nosession -multiInst</Command>
                      </UserDefinedCommands>
                      <PluginCommands />
                      <ScintillaKeys />
                  </NotepadPlus>
                  

                  —

                  moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

                  P 1 Reply Last reply Dec 24, 2024, 8:22 PM Reply Quote 0
                  • P
                    PeterJones @Robert Or Janet Diebel
                    last edited by PeterJones Dec 24, 2024, 8:22 PM Dec 24, 2024, 8:22 PM

                    @Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:

                    After changes to the file, or a new file copied in, the Macros I can see in the file are no longer available.

                    It works for me. I pasted your example into my active shortcuts.xml file, saved, exited Notepad++, and restarted, and it saw the new macro just fine.

                    3194e349-0f6d-4682-a113-c79cd83af7bf-image.png

                    Are you sure you did things in the right order? The User Manual describes the order of events you must follow if you want to edit a Notepad++ config file with Notepad++ – you have to exit Notepad++ (to make sure that all the changes Notepad++ has queued up are written), then start Notepad++, then do the manual edit, then save and exit (without doing any changes in the GUI) then restart. If you don’t follow that order, Notepad++ will overwrite your changes (if there had been any GUI changes that affect that file) when it exits,

                    1 Reply Last reply Reply Quote 1
                    • A
                      Alan Kilborn @Robert Or Janet Diebel
                      last edited by PeterJones Dec 25, 2024, 5:57 PM Dec 24, 2024, 8:37 PM

                      @Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:

                      Are comments allowed in shortcuts.xml?

                      You can do this:

                      <Action type="1" message="2172" wParam="0" lParam="0" sParam="I am a comment!!!!!!!!" />

                      1 Reply Last reply Reply Quote 2
                      12 out of 12
                      • First post
                        12/12
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors