Using plug-ins in macro
I am trying to create a macro which also uses the JSON Viewer -> Format JSON to “pretty print” some JSON. When I look at the macro in Shortcuts.xml there does not appear to be any lines associated with the execution of the plug-in from the NPP menu.
Is it even possible to use plug-ins in a macro?
Thanks in advance
Notepad++ v8.1.9 (32-bit)
Build time : Oct 21 2021 - 23:32:04
Path : C:\Program Files (x86)\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 2009
OS Build : 19042.1348
Current ANSI codepage : 1252
Plugins : ComparePlugin.dll JSLintNpp.dll mimeTools.dll NppConverter.dll NppExec.dll NppExport.dll NPPJSONViewer.dll NppUISpy.dll RegexTrainer.dll SpellChecker.dll
PeterJones last edited by
You cannot record a macro to call a plugin menu command.
However, you can manually create/edit the macro to insert those commands. To get the command ID, you need to use a plugin like NppUISpy – ooh, you already have it; great!. However, there is a caveat: plugin menu ID’s are not constant: if you add or remove a plugin, or if you update a plugin and it changes the number of menu entries, the command ID may change.
For more on this, see this post, in which I show an example of the steps for adding an XML Tools menu command to the macro. The procedure for JSON Viewer would be similar.
@peterjones Thanks so much for your prompt response :)
@peterjones Looked at your linked post. This explains why all my macros were removed when I edited the shortcuts.xml. Anyway, my plug-in has a subcommand. Is there a way to specify that via a xParam ? There is also a keyboard shortcut for the subcommand. Is there a way to execute that in the macro?
@PeterJones Nevermind, the wParam is already the plugin subcommand.
PeterJones last edited by
my plug-in has a subcommand. Is there a way to specify that via a xParam ?
I am not sure what you mean by “subcommand”. In Windows menus, there are either separator lines, submenus, or command entries. Command IDs are only available for command entries, nothing else has a command ID.
For example, as NppUISpy shows in my current Notepad++ environment:
Plugins > Python Script is a submenu, so it has a command ID of “0”. Then it has some actions which are 22108-22111. Then it has a Scripts submenu with id=0. Then there is the
startupscript command entry inside that menu, with id=23034, another couple of submenus, then a script that is called
aaa123with id=23127. So if I wanted to run the
aaa123script from a macro, I could create a macro that calls that number, such as
<Macro name="Example" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="2" message="0" wParam="23127" lParam="0" sParam="" /> </Macro>
There is also a keyboard shortcut for the subcommand. Is there a way to execute that in the macro?
If that keyboard shortcut is editable using the Notepad++ built-in shortcut mapper, then the chances are, it will be able to run that using the number that UI Spy shows you. But plugins can also define keyboard shortcuts not using the Shortcut Mapper (though that’s an evil practice, since it makes for unknown shortcut conflicts) – so having a shortcut is not a guarantee that the plugin is playing nice.
(note: didn’t see your “nevermind” until after I had the whole post basically written, so I am including it for future readers, and you if you care to have the extra info)