Community
    • Login

    Can I invoke a plugin from a macro?

    Scheduled Pinned Locked Moved General Discussion
    14 Posts 5 Posters 1.9k 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.
    • PeterJonesP
      PeterJones @ggodhner 0
      last edited by PeterJones

      @ggodhner-0 ,

      While @WinterSilence is correct, and there is a way to send messages directly to a plugin, the 41001 isn’t the wrong wParam.
      That correctly creates a new file.

      What you are trying to do is just run a menu entry, but not a menu entry that the macro record function will admit to – there are many that it doesn’t record. However, every menu does have a command ID, and if you know that ID, you can send it using the same syntax that gets used for the 41001/41003 File New/Close menu commands.

      Some plugins use fixed values for their command ID for their menu; others might use dynamic values. You can check the source code, and if it is fixed, you should be able to find the IDM_xxxx constant or similar, often in an .rc file, or the .h that feeds it. But that’s tedious.

      Plugins Admin allows you to install NppUISpy, which allows you to navigate through the menu system and look up the menu command ID for any entry. When I did that, it said 22033. I’m pretty sure the MIME Tools plugin would use static/fixed command IDs, so that should be consistent.

      I closed all Notepad++, edited shortcuts.xml , and added the macro to SelectAll, QuotedPrintableDecode, and SelectAll:

              <Macro name="SelectAll-QuotedPrintableDecode" Ctrl="no" Alt="no" Shift="no" Key="0">
                  <Action type="0" message="2013" wParam="0" lParam="0" sParam="" />
                  <Action type="2" message="0" wParam="22033" lParam="0" sParam="" />
                  <Action type="0" message="2013" wParam="0" lParam="0" sParam="" />
              </Macro>
      

      When I start Notepad++ again, that macro is available; if I manual QP-Encode, then run the macro, it ends with it being all selected and QuotedPrintable has been decoded again.

      —

      • Macro Syntax in shortcuts.xml: https://npp-user-manual.org/docs/config-files/#macros
      • NPPM_MSGTOPLUGIN: https://npp-user-manual.org/docs/plugin-communication/#nppm-msgtoplugin
      PeterJonesP 1 Reply Last reply Reply Quote 2
      • PeterJonesP
        PeterJones @PeterJones
        last edited by

        @PeterJones said in Can I invoke a plugin from a macro?:

        I’m pretty sure the MIME Tools plugin would use static/fixed command IDs

        However, I cannot find 22033 anywhere in the MIME Tools source code, so maybe that number does change. If it doesn’t work for you, I recommend NppUISpy to find the right value for your installation.

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

          I said,

          every menu does have a command ID, and if you know that ID, you can send it using the same syntax

          While that should work as I understand things, there may be instances where it doesn’t, or where it doesn’t do what you think it should.

          But I think it’s a safe bet to send a type=“2” message to just about any menu command, and it’s something I’d be willing to at least experiment with, in similar circumstances.

          1 Reply Last reply Reply Quote 0
          • ggodhner 0G
            ggodhner 0
            last edited by

            Thanks, Peter. That’s just what I needed! I did have to install NppUISpy, and it turned out to be 22024 on my system, so it appears to be dynamically assigned. My macro now works as I intended, and my frustration is gone. I’m so glad you were able to help.

            ggodhner 0G PeterJonesP 2 Replies Last reply Reply Quote 1
            • ggodhner 0G
              ggodhner 0 @ggodhner 0
              last edited by

              In case you’re interested, here’s the final macro I came up with:

                  <Macro name="Mime-Copy-Decoded" Ctrl="yes" Alt="yes" Shift="yes" Key="77">
              			<!-- 	Copy selection, paste clipboard into a new,
              					temporary buffer, then select it all, perform
              					MIME Quoted-printable-Decode on it
              					from the MIME Tools plugin, again select all,
              					then copy the result.
              					Then undo the decode and the paste,
              					and close the temporary buffer,
              					leaving the decoded result in the clipboard.
              			-->
                      <Action type="0" message="2178" wParam="0" lParam="0" sParam="" />
              			<!-- 2178 = Copy -->
                      <Action type="0" message="2422" wParam="0" lParam="0" sParam="" />
              			<!-- 2422 = SetSelectionMode -->
                      <Action type="0" message="2325" wParam="0" lParam="0" sParam="" />
              			<!-- 2325 = Cancel -->
                      <Action type="2" message="0" wParam="41001" lParam="0" sParam="" />
              			<!-- 41001 = New -->
                      <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
              			<!-- 2179 = Paste -->
                      <Action type="0" message="2013" wParam="0" lParam="0" sParam="" />
              			<!-- 2013 = SelectAll -->
              		<Action type="2" message="0" wParam="22024" lParam="0" sParam="" />
              			<!-- 22024 = Quoted-printable-Decode
              				as determined by NppUISpy
              				https://community.notepad-plus-plus.org/topic/19565/
              				-->
                      <Action type="0" message="2013" wParam="0" lParam="0" sParam="" />
              			<!-- 2013 = SelectAll -->
                      <Action type="0" message="2178" wParam="0" lParam="0" sParam="" />
              			<!-- 2178 = Copy -->
                      <Action type="0" message="2422" wParam="0" lParam="0" sParam="" />
              			<!-- 2422 = SetSelectionMode -->
                      <Action type="0" message="2325" wParam="0" lParam="0" sParam="" />
              			<!-- 2325 = Cancel -->
                      <Action type="2" message="0" wParam="42003" lParam="0" sParam="" />
              			<!-- 42003 = Undo -->
                      <Action type="2" message="0" wParam="42003" lParam="0" sParam="" />
              			<!-- 42003 = Undo -->
                      <Action type="2" message="0" wParam="41003" lParam="0" sParam="" />
              			<!-- 41003 = Close-->
                  </Macro>
              
              1 Reply Last reply Reply Quote 2
              • PeterJonesP
                PeterJones @ggodhner 0
                last edited by

                @ggodhner-0 said in Can I invoke a plugin from a macro?:

                it turned out to be 22024 on my system

                Glad it’s working for you for now.

                Unfortunately, since it’s dynamic, any time you add or remove plugins, or update plugins, or update Notepad++, it’s likely that the 22024 will change. But, as long as you are expecting that and willing to re-run NppUISpy again after such circumstances, then it’s okay.

                If you want something less fragile, you might look into a scripting plugin, like PythonScript, which has notepad.runPluginCommand(), which will invoke a plugin sub-command by string. So, for you, notepad.runPluginCommand("MIME Tools", "Quoted-printable Decode") That’s more likely to work even with changes in plugins and versions; you can add shortcuts to PythonScript scripts; let us know if you want help with that.

                1 Reply Last reply Reply Quote 1
                • EkopalypseE
                  Ekopalypse
                  last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • WinterSilenceW
                    WinterSilence
                    last edited by

                    @PeterJones said in Can I invoke a plugin from a macro?:

                    and there is a way to send messages directly to a plugin, the 41001 isn’t the wrong wParam.
                    That correctly creates a new file.

                    i talk about wrong type, not wParam

                    PeterJonesP 1 Reply Last reply Reply Quote 0
                    • PeterJonesP
                      PeterJones @WinterSilence
                      last edited by

                      @WinterSilence said in Can I invoke a plugin from a macro?:

                      i talk about wrong type, not wParam

                      No. You misunderstood. There wasn’t anything “wrong” with the script as recorded, except that the macro recorder completely skipped activating the plugin menu for @ggodhner-0 . The individual interpretations that the OP used for each of those recorded lines was absolutely correct.

                      NPPM_MSGTOPLUGIN has nothing to do with “type”, nor with the original problem posted. NPPM_MSGTOPLUGIN is only useful if you want to do a SendMessage to a plugin, which is not what the original requester wanted. The MIME Tools plugin doesn’t have any special messages defined for getting access to the encode/decode functions, so sending an NPPM_MSGTOPLUGIN would do nothing for that plugin. The MIME Tools plugin just links the functions to menu commands. To do a menu command, as I described, you issue a type=“2” with the command ID as the wParam.

                      1 Reply Last reply Reply Quote 2
                      • ggodhner 0G
                        ggodhner 0
                        last edited by

                        @PeterJones Yes, I would like some help. I was able to write a PythonScript script to do my little task, but it’s at the 4th level in the menu, which makes it inconvenient, and there doesn’t appear to be any way to invoke it with a keyboard shortcut. The Shortcut Mapper doesn’t provide access to PythonScript scripts, and invoking them directly doesn’t work, so I don’t think I can make it a UserDefinedCommand. If there isn’t a solution I’m unaware of, then I’m better off with the macro that needs updating occasionally. Is there some other way to run it or assign a shortcut?

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

                          @ggodhner-0 said in Can I invoke a plugin from a macro?:

                          I was able to write a PythonScript script to do my little task, but it’s at the 4th level in the menu, which makes it inconvenient, and there doesn’t appear to be any way to invoke it with a keyboard shortcut. The Shortcut Mapper doesn’t provide access to PythonScript scripts,

                          Use the Configuration… entry in the Plugins > Python Script menu and Add your script so that it appears in the Menu Items area. Then, after a restart of Notepad++, your script should be available to be assigned a keycombo via the Shortcut Mapper.

                          ggodhner 0G 1 Reply Last reply Reply Quote 2
                          • ggodhner 0G
                            ggodhner 0 @Alan Kilborn
                            last edited by

                            @Alan-Kilborn Perfect! Just exactly what I needed! Now I’m ready to go! Many thanks to both of you!

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