Can I invoke a plugin from a macro?
-
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.
-
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.
-
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>
-
@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. -
This post is deleted! -
@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
-
@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.
-
@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?
-
@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.
-
@Alan-Kilborn Perfect! Just exactly what I needed! Now I’m ready to go! Many thanks to both of you!