Community
    • Login

    Running a macro on all the open docs ?.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    51 Posts 4 Posters 1.1k 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.
    • Robert Or Janet DiebelR
      Robert Or Janet Diebel @Alan Kilborn
      last edited by

      @Alan-Kilborn My MACRO:

      <?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="\c2Book\v2Verse" Ctrl="no" Alt="no" Shift="no" Key="0">
                  <Action type="2" message="0" wParam="42083" lParam="0" sParam="" />
                  <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                  <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)^\\c (\d+)(?=(.*\R)+?\\toc2 (.+)$)" />
                  <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                  <Action type="3" message="1602" wParam="0" lParam="0" sParam="${3} ${1}" />
                  <Action type="3" message="1702" wParam="0" lParam="512" 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="(?-is)\\v (?=(?s:.+?^(\u[\u\l -]+ \d+$)))" />
                  <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                  <Action type="3" message="1602" wParam="0" lParam="0" sParam="${1}:" />
                  <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />
                  <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                  <Action type="2" message="0" wParam="42083" lParam="0" sParam="" />
              </Macro>
              <Macro name="RemoveUSFM" 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="\\f.*?\\f\*" />
                  <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="770" 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="\\fig.*?\\fig\*" />
                  <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="770" 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="\\x.*?\\x\*" />
                  <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="770" 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\\s2.*$|\r\n\\s1.*$|\r\n\\s.*$" />
                  <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="770" 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\\ms1.*$|\r\n\\r.*$" />
                  <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="770" 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="\\\+nd\*|\\\+nd\s|\\nd\*|\\nd\s|\\k\*|\\k\s" />
                  <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="770" 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="\\\+tl\*|\\\+tl\s|\\tl\*|\\tl\s" />
                  <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="770" 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="\\qs\*|\\qs\s" />
                  <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="770" 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\\m|\r\n\\p|\r\n\\b" />
                  <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="770" 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\\q4|\r\n\\q3" />
                  <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="770" 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\\q2|\r\n\\q1|\r\n\\q" />
                  <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="770" 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="\\add\*" />
                  <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="770" 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="\\add\s" />
                  <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="770" 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="\\png\*|\\png\s" />
                  <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="770" 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="\\pn\*|\\pn\s" />
                  <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="770" 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\\d\s" />
                  <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="770" sParam="" />
                  <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
              </Macro>
              <Macro name="RemovePreamble" 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\s.*^(\w+\s1)$" />
                  <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                  <Action type="3" message="1602" wParam="0" lParam="0" sParam="${1}" />
                  <Action type="3" message="1702" wParam="0" lParam="1536" sParam="" />
                  <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
              </Macro>
              <Macro name="RemovePreamble2" 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-i)\\id.+?\\toc2 (.+?)\R.*?(?=^\1 \d+$)" />
                  <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="512" sParam="" />
                  <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
              </Macro>
              <Macro name="Space2Tab" 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="^(\w+\s\d+:\d+)\s(.*)$" />
                  <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                  <Action type="3" message="1602" wParam="0" lParam="0" sParam="$1\t$2" />
                  <Action type="3" message="1702" wParam="0" lParam="512" 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>
      
      
      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Robert Or Janet Diebel
        last edited by

        @Robert-Or-Janet-Diebel said in Running a macro on all the open docs ?.:

        <Macro name="\c2Book\v2Verse" ...

        Why in the world would you put backslashes into the name of a macro?!?! You obviously know that backslashes are important to regex, because your macros include regex with backslashes! It turns out, and they are also important in lots of other things, including programming language strings.

        I know that’s not the cause of your imagined “incompatibility” between Notepad++ v8.7.5 (or newer) and PythonScript 3… but it does appear to be the culprit for your other difficulties, when you do have a working combination of Notepad++ and PythonScript 2.

        Despite your lack of ability to correctly install it, PythonScript 3.0.22 works just fine with v8.7.9 and v8.7.5. My Experiments with PythonScript 3.0.22 with v8.7.9 show that calling notepad.runMenuCommand("Macro", "\c2Book\v2Verse") causes an error, specifically,

        C:\usr\local\apps\npp\npp.8.7.9.portable.x64-withPS3022\plugins\Config\PythonScript\scripts\MacroAllFiles_BadBackslash.py:13: SyntaxWarning: invalid escape sequence '\c'
          notepad.runMenuCommand("Macro", "\c2Book\v2Verse")
        

        When using notepad.runMenuCommand("Macro", "\\c2Book\\v2Verse") in the script, it works. If we had known that you had backslashes in your macro name earlier in the process, we could have warned you about that issue, and you wouldn’t have had any difficulty once you got PythonScript installed properly

        I’m going to give up trying to help you install PythonScript 3, even though I know it works just fine. Instead, just use Plugins Admin to install the most recent PythonScript 2 (right now, it’s 2.1.0 in the Plugins Admin; I don’t know why you installed 2.0 instead). With that, and using the modified string in notepad.runMenuCommand("Macro", "\\c2Book\\v2Verse"), the script will work for you (or, if you rename your macro so it doesn’t have backslashes, then you can just use the literal name of the macro in the string)

        Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 1
        • Robert Or Janet DiebelR
          Robert Or Janet Diebel @PeterJones
          last edited by

          @PeterJones Thank you. I will change and try again.

          1 Reply Last reply Reply Quote 0
          • Robert Or Janet DiebelR
            Robert Or Janet Diebel @PeterJones
            last edited by

            @PeterJones I appreciate all your efforts. After a very thorough remove, cleanup and re-install of both Notepad++ and PythonScript My initial tests show it is working. Thanx

            1 Reply Last reply Reply Quote 0
            • Robert Or Janet DiebelR
              Robert Or Janet Diebel @Alan Kilborn
              last edited by

              @Alan-Kilborn I appreciate all your efforts. After a very thorough remove, cleanup and re-install of both Notepad++ and PythonScript My initial tests show it is working. Thanx

              1 Reply Last reply Reply Quote 1
              • Robert Or Janet DiebelR
                Robert Or Janet Diebel @Alan Kilborn
                last edited by

                @Alan-Kilborn Some “Scope Creep” I know, but could I get your input on if and how this might be possible?

                I load *.SFM files from an SFM folder.
                I run my MACROs on them.
                I wish to SAVE ALL with a different extention *.txt to a differnt (TXT) folder.
                I can “save as” with extention changed manually.
                But I thought it might be do-able in a more automated way.
                As always, all help much appreciated.

                Alan KilbornA 2 Replies Last reply Reply Quote 0
                • Alan KilbornA
                  Alan Kilborn @Robert Or Janet Diebel
                  last edited by

                  @Robert-Or-Janet-Diebel said :

                  could I get your input on…

                  You’d have to go full-on scripting to achieve that; can’t be done in a macro, but easily doable with scripting. If you go that route, perhaps it makes sense to translate your macro into script commands as well.

                  PeterJonesP 1 Reply Last reply Reply Quote 1
                  • PeterJonesP
                    PeterJones @Alan Kilborn
                    last edited by

                    @Alan-Kilborn said in Running a macro on all the open docs ?.:

                    @Robert-Or-Janet-Diebel said :

                    could I get your input on…

                    You’d have to go full-on scripting to achieve that;

                    @Robert-Or-Janet-Diebel, since you are now using my script to run the macro on every file anyway, adding the calculation to get the new filename based on the old .txt name shouldn’t be difficult, and that could be passed into notepad.saveAs() – these lines would go immediately after the notepad.runMenuCommand(...) line, at the same indentation level.

                    If you go that route, perhaps it makes sense to translate your macro into script commands as well.

                    it probably does make sense to translate the two search-and-replaces from the macro into native pythonscript. if I’d known, at the time I was writing that script, that the macro just did one or two s+r actions, I would have asked what those regex were specifically, and we could have bypassed the whole macro-naming fiasco by running the macro in the PythonScript.

                    But I’m not sure I’m interested in being the one to add the filename calculation, or substitue the notepad.runMenuCommand(...) with the editor.research(...) or walk @Robert-Or-Janet-Diebel through the process of typing in those lines into the correct place in the script, because I have a feeling that would be another huge number of back-and-forths.

                    Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 2
                    • Robert Or Janet DiebelR
                      Robert Or Janet Diebel @PeterJones
                      last edited by

                      @PeterJones Well, what you have helped me with previously is working great. and I thank you very much. It is good to know it is possible though.

                      1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @Robert Or Janet Diebel
                        last edited by

                        @Robert-Or-Janet-Diebel said :

                        I wish to SAVE ALL with a different extention *.txt to a differnt (TXT) folder.

                        Just to show how only this part might be done in scripting:

                        import os
                        save_copy_folder = r'c:\junk\sfm_files'  # folder of your choice
                        for (pathname, buffer_id, index, view) in notepad.getFiles():
                            if pathname.lower().endswith('.sfm'):
                                sfm_filename = pathname.rsplit(os.sep, 1)[-1]
                                txt_filename = sfm_filename[:-3] + 'txt'  # strip off sfm extension and add txt
                                save_copy_pathname = os.path.join(save_copy_folder, txt_filename)
                                notepad.activateFile(pathname)
                                notepad.saveAsCopy(save_copy_pathname)
                        
                        Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 0
                        • Robert Or Janet DiebelR
                          Robert Or Janet Diebel @Alan Kilborn
                          last edited by

                          @Alan-Kilborn Thank you Alan.

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