• Login
Community
  • Login

error in macros in Notepad++

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 931 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.
  • H
    Heinz Berecz 0
    last edited by Nov 16, 2021, 2:41 PM

    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?

    P 1 Reply Last reply Nov 16, 2021, 3:31 PM Reply Quote 1
    • P
      PeterJones @Heinz Berecz 0
      last edited by PeterJones Nov 16, 2021, 3:34 PM Nov 16, 2021, 3:31 PM

      @heinz-berecz-0 ,

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

      H 1 Reply Last reply Nov 22, 2021, 3:24 PM Reply Quote 2
      • H
        Heinz Berecz 0 @PeterJones
        last edited by Nov 22, 2021, 3:24 PM

        @peterjones
        how can I switch over to PythonScript?

        E 1 Reply Last reply Nov 23, 2021, 9:42 AM Reply Quote 0
        • E
          Ekopalypse @Heinz Berecz 0
          last edited by Nov 23, 2021, 9:42 AM

          @heinz-berecz-0

          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)

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