Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Macro acting out

    Help wanted · · · – – – · · ·
    macro
    3
    5
    3144
    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.
    • Lajos Andrejkovics
      Lajos Andrejkovics last edited by

      What am I doing wrong? Here’s what I do:

      1. Open a txt file
      2. Macro > Start recording
      3. Encoding > Convert to UTF with BOM
      4. File > Save
      5. File > Close
      6. Macro > End recording

      So what this macro should do is change the encoding of the file I run it on, save it and close it. Right?

      WRONG… !

      All it does when I try to run it (either by Playback or I save it and run it with from the menu) is empties the content of the opened txt and pastes what was on my clipboard… WTF? WHY???

      All help is appreciated… Thanks!

      Claudia Frank 1 Reply Last reply Reply Quote 0
      • Claudia Frank
        Claudia Frank @Lajos Andrejkovics last edited by

        @Lajos-Andrejkovics

        something seems to be broken - let’s create the macro manually.
        (Depending on your installation the config files are either under the install directory
        or under %APPDATA%\notepad++)

        Open shortcuts.xml file in one view and english.xml in the other view.
        Duplicate an existing macro and give it a different name (I call it EncodeUTF-BOM for now)

        When checking this page
        we will see that a macro is able to send 4 types of messages which are identified by an integer

        0 for Scintilla messages that do not pass a string as second parameter
        1 for Scintilla messages that pass a string as second parameter
        2 for Notepad++ defined commands
        3 for search and replace recording
        

        For your purpose we need 2 (the notepad defined messages) only.

        Goto the english.xml file. Within this file you see the messages and their ids like

                    <Commands>
                        <Item id="41001" name="&amp;New"/>
                        <Item id="41002" name="&amp;Open"/>
                        <Item id="41019" name="Explorer"/>
                        <Item id="41020" name="cmd"/>
                        <Item id="41003" name="Close"/>
                        <Item id="41004" name="C&amp;lose All"/>
                        <Item id="41005" name="Close All BUT Current Document"/>
                        <Item id="41009" name="Close All to the Left"/>
                        <Item id="41018" name="Close All to the Right"/>
                        <Item id="41006" name="&amp;Save"/>
        

        for your request we need the message ids for Convert to UTF-8, Save, and Close which are 45011, 41006 and 41003.

        Go back to shortcuts.xml and create the macro like this

            <Macro name="EncodeUTF-BOM" Ctrl="no" Alt="no" Shift="no" Key="0">
                <Action type="2" message="0" wParam="45011" lParam="0" sParam="" />
                <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
                <Action type="2" message="0" wParam="41003" lParam="0" sParam="" />
            </Macro>
        

        Restart npp and (hopefully) it should be done. You should see the new macro under the Macro menu.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 2
        • Lajos Andrejkovics
          Lajos Andrejkovics last edited by

          Thank you Claudia, it works! Now I can write my macros instead of ‘recording’ them… great! Problem solved :)

          Scott Sumner 1 Reply Last reply Reply Quote 0
          • Scott Sumner
            Scott Sumner @Lajos Andrejkovics last edited by

            @Lajos-Andrejkovics said:

            Now I can write my macros instead of ‘recording’ them

            Just a hint: I find that trying to record them first, then attempting hand-editing if they don’t work is a viable approach. Sometimes the recording process is imperfect, but often in these cases the bulk of it is correct and it only needs a little tweaking. This is better than going thru the drudgework of writing the whole thing from scratch. YMMV. :-)

            Scott Sumner 1 Reply Last reply Reply Quote 1
            • Scott Sumner
              Scott Sumner @Scott Sumner last edited by

              @Scott-Sumner said:

              record them first, then attempting hand-editing if they don’t work

              When you record a macro, you need to save it (and name it) and then restart Notepad++. The action of quitting Notepad++ forces shortcuts.xml to be written if needed (like if you saved a recorded macro…or changed a shortcut mapping…). If you don’t do this, and open shortcuts.xml for editing, not only will you not see the macro you want to hand-edit, but Notepad++ will overwrite any changes you now make when it finally exits.

              1 Reply Last reply Reply Quote 0
              • Referenced by  Heinz Berecz 0 Heinz Berecz 0 
              • First post
                Last post
              Copyright © 2014 NodeBB Forums | Contributors