• Login
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.
  • G
    ggodhner 0
    last edited by Jun 16, 2020, 7:45 PM

    I’ve tried to create a macro that invokes a plugin action, but the resulting macro ignores the plugin action. Is there some other way besides recording the macro to cause the macro to invoke the plugin? Here’s what I’ve done:

    Having selected a Mime-Encoded link:

    Start Recording
    1. Copy
    2. New
    3. Paste
    4. Select All
    5. Plugins -> MIME Tools -> Quoted-printable-Decode
    6. Select All
    7. Copy
    8. Undo
    9. Undo
    10. Close
    Stop Recording
    Save Current Recorded Macro…
    “Mime-Copy-Decoded” Control-Alt-Shift-M

    Here’s the macro as recorded, as it appears in the shortcuts.xml file:
    <Macro name=“Mime-Copy-Decoded” Ctrl=“yes” Alt=“yes” Shift=“yes” Key=“77”>
    <Action type=“0” message=“2178” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“0” message=“2422” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“0” message=“2325” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“2” message=“0” wParam=“41001” lParam=“0” sParam=“” />
    <Action type=“0” message=“2179” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“0” message=“2013” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“0” message=“2013” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“0” message=“2178” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“0” message=“2422” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“0” message=“2325” wParam=“0” lParam=“0” sParam=“” />
    <Action type=“2” message=“0” wParam=“41003” lParam=“0” sParam=“” />
    </Macro>

    Here are the interpretations of the actions in the file:
    2178 = Copy
    2422 = SetSelectionMode
    2325 = Cancel
    41001 = New
    2179 = Paste
    2013 = SelectAll
    Should have been Quoted-printable-Decode here!
    2013 = SelectAll
    2178 = Copy
    2422 = SetSelectionMode
    2325 = Cancel
    41003 = Close

    I would appreciate any help resolving this difficulty.

    W P 2 Replies Last reply Jun 18, 2020, 6:49 AM Reply Quote 0
    • W
      WinterSilence @ggodhner 0
      last edited by Jun 18, 2020, 6:49 AM

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

      41001

      wrong type, see NPPM_MSGTOPLUGIN

      1 Reply Last reply Reply Quote 1
      • P
        PeterJones @ggodhner 0
        last edited by PeterJones Jun 18, 2020, 1:22 PM Jun 18, 2020, 1:20 PM

        @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
        P 1 Reply Last reply Jun 18, 2020, 1:29 PM Reply Quote 2
        • P
          PeterJones @PeterJones
          last edited by Jun 18, 2020, 1:29 PM

          @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.

          P 1 Reply Last reply Jun 18, 2020, 1:33 PM Reply Quote 0
          • P
            PeterJones @PeterJones
            last edited by Jun 18, 2020, 1:33 PM

            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
            • G
              ggodhner 0
              last edited by Jun 18, 2020, 1:37 PM

              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.

              G P 2 Replies Last reply Jun 18, 2020, 1:49 PM Reply Quote 1
              • G
                ggodhner 0 @ggodhner 0
                last edited by Jun 18, 2020, 1:49 PM

                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
                • P
                  PeterJones @ggodhner 0
                  last edited by Jun 18, 2020, 1:54 PM

                  @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
                  • E
                    Ekopalypse
                    last edited by Jun 18, 2020, 1:56 PM

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • W
                      WinterSilence
                      last edited by Jun 18, 2020, 5:49 PM

                      @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

                      P 1 Reply Last reply Jun 18, 2020, 6:02 PM Reply Quote 0
                      • P
                        PeterJones @WinterSilence
                        last edited by Jun 18, 2020, 6:02 PM

                        @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
                        • G
                          ggodhner 0
                          last edited by Jun 18, 2020, 8:47 PM

                          @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?

                          A 1 Reply Last reply Jun 18, 2020, 8:51 PM Reply Quote 1
                          • A
                            Alan Kilborn @ggodhner 0
                            last edited by Jun 18, 2020, 8:51 PM

                            @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.

                            G 1 Reply Last reply Jun 18, 2020, 8:57 PM Reply Quote 2
                            • G
                              ggodhner 0 @Alan Kilborn
                              last edited by Jun 18, 2020, 8:57 PM

                              @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
                              10 out of 14
                              • First post
                                10/14
                                Last post
                              The Community of users of the Notepad++ text editor.
                              Powered by NodeBB | Contributors