error in macros in Notepad++
-
I recorded the action “Convert to ANSI” as described in user.manual/documentation/notepad-user-manual/macros.html and saved the macro as “Convert to ANSI”.
When I startet the macro it did not work but replaced the content of the document by the content of the clipboard.
The shortcuts.xml file contained the following lines:<Macro name=“Convert to ANSI” Ctrl=“no” Alt=“yes” Shift=“no” Key=“123”>
<Action type=“1” message=“2170” wParam=“0” lParam=“0” sParam=“k” />I replaced this line by
<Action type=“2” message=“0” wParam=“45009” lParam=“0” sParam=“” />
and the macro did work.The error is already described in https://community.notepad-plus-plus.org/topic/14642/macro-acting-out
Is there a possibility to avoid this error? -
<Macro name=“Convert to ANSI” Ctrl=“no” Alt=“yes” Shift=“no” Key=“123”> <Action type=“1” message=“2170” wParam=“0” lParam=“0” sParam=“k” />
That’s not what I get when I record that sequence. I get
<Macro name="Converter" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2004" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2179" 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="" /> </Macro>
… however, the behavior you described:
… replaced the content of the document by the content of the clipboard.
is what I get when I play that message. And it makes sense, because
- 2004 = Clear All => erases entire document
- 2179 = Paste
- 2422 = Set Selection Mode
- 2325 = Cancel
So, what gets recorded does not make sense, but what happens when I play that specific recording does make sense, given the nonsensical recording.
Unfortunately, the macro-recording system is not perfect, and the macro system in general has limitations (intentional and probably unintentional).
I know there’s only a limited list of scintilla messages that can be recorded in the macro… I thought that more of the Notepad++ menu items were allowed, but maybe the Encoding>ConvertToX aren’t in the list (but I am not able to find where in the codebase that the IDM_xxx portion of macro recording occurs).
My general procedure is to check if a macro records the actions I think it should, and to edit the macro manually if it isn’t right. (I also usually change the individual keystrokes – like multiple type-a-character Actions – into a single typing action that does the whole string at once.)
But if a Macro fights me too much, making it too much effort to get right, I’m likely to switch over to PythonScript instead – which gives access to basically all the Notepad++ menu commands (either as methods on the
notepad
object or through the run-menu-command methods) as well as syntax methods for running most Sctintilla commands (and those that aren’t implemented can be hacked using SendMessage).—
BTW: once you’re certain you have a bug or feature request (and I think it’s confirmed wonky behavior in this instance), we have a FAQ entry which explains where to make an official request, rather than just talking with fellow users here in the Community Forum. -
@peterjones
how can I switch over to PythonScript? -
by installing the PythonScript plugin via PluginAdmin and using the notepad object with its menuCommand, runMenuCommand and runPluginCommand methods.
Note that you can use the standard help function that Python normally has from within the PythonScript console window.
For example:help(notepad.runMenuCommand)