Creating and running macros

  • Further testing shows that if you select the macro name from the pulldown, it also doesn’t work. Just for winks and grins, I tried running the macro multiple times option, selected 1 as the occurrence, then the name, that didn’t work either. Evidently something in that run engine is broken.;

  • Could you supply a description of what you intend the macro to do? You might also want to grab that portion from the shortcuts.xml file since you seem to have saved it.

    When inserting the macro code into here, put a blank line before and 4 spaces on the line before inserting the code. This will make it show as per my example above (in a black box).

    This is probably going to be a bit of a long shot as macro code is very hard to read. With your description I may be able to make another version and test.

    At the moment I’m inclined to think it’s the idea behind the macro that’s flawed, not the engine running the macro. When I created my first macro, after successfully running the regexs normally I finished up with a mess. I couldn’t understand how something which worked, then failed when converted to a macro. I’m still not sure where I went wrong, and yes I have to admit it must have been my mistake, perhaps in the typing, but I eventually successfully created several macros that all work exactly as I intended.


  • I think we have a miscommunication issue here. It’s not that the macro is returning 0 results - I can work with that. It’s that it’s not executing AT ALL, regardless if I select it from the pulldown or use the key shortcut. I could accept a 0 result - but the fact that it doesn’t appear to be executing is the issue.
    Here is my attempt at inserting the recorded code;

    <?xml version="1.0"?>

    -<Macro Key=“65” Shift=“yes” Alt=“no” Ctrl=“yes” name=“DSC”>
    <Action sParam="" lParam=“0” wParam=“0” message=“1700” type=“3”/>
    <Action sParam=“DSC” lParam=“0” wParam=“0” message=“1601” type=“3”/>
    <Action sParam="" lParam=“0” wParam=“0” message=“1625” type=“3”/>
    <Action sParam="" lParam=“0” wParam=“0” message=“1702” type=“3”/>
    <Action sParam="" lParam=“1641” wParam=“0” message=“1701” type=“3”/>

  • @Michael-Agner ,

    Unfortunately, your whole shortcuts.xml snippet didn’t make it into the text box, so it’s hard to tell exactly the contents: every line of the quoted text needs to be indented at least 4 spaces. If you are having difficulty with that, you can use a trick of having

    <embed here>

    Which gets rid of the need to indent. It will render like:

    <embed here>

    You can see the PREVIEW window on the right, which will show what your post will look like to us.

    Anyway, back to details, rather than meta-content:

    None of my shortcuts.xml include the <?xml version="1.0"?>, so I was surprised to see that quoted. And you’ve got some funny hyphens that appear to be before certain items, so I don’t know whether those are really there, and whether they are what’s messing it up or not.

        ... redacted ...
        <Macro name="Trim Trailing Space and Save" Ctrl="yes" Alt="no" Shift="no" Key="83">
            <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
            <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
        <Macro name="Trim Trailing Space and Save All" Ctrl="yes" Alt="yes" Shift="yes" Key="83">
            <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
            <Action type="2" message="0" wParam="41007" lParam="0" sParam="" />
        <Macro name="RecordedMacro" Ctrl="no" Alt="no" Shift="no" Key="0">
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" />
    ... redacted ...

    For mine, that last, short macro called “RecordedMacro” was just recoding me typing a C in the editor window. Try putting that macro in your %AppData%\Notepad++\shortcuts.xml, and see if after reloading Notepad++, whether that will properly insert the letter C or not.

    If that works, then try inserting the C action at the beginning and end of your “DSC” macro, and see whether both C's are typed (might want to change the second to a D, to distinguish the two). Thus, try something like:

            <Macro name="RecordedMacro" Ctrl="no" Alt="no" Shift="no" Key="0">
                <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" />
            <Macro Key="65" Shift="yes" Alt="no" Ctrl="yes" name="DSC">
                <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" />
                <Action sParam="" lParam="0" wParam="0" message="1700" type="3"/>
                <Action sParam="DSC" lParam="0" wParam="0" message="1601" type="3"/>
                <Action sParam="" lParam="0" wParam="0" message="1625" type="3"/>
                <Action sParam="" lParam="0" wParam="0" message="1702" type="3"/>
                <Action sParam="" lParam="1641" wParam="0" message="1701" type="3"/>
                <Action type="1" message="2170" wParam="0" lParam="0" sParam="D" />

    See whether the “RecordedMacro” properly does the C, and whether the “DSC” macro does the C and D.

    Don’t forget you have to exit Notepad++ and re-enter for the changes to shortcuts.xml. (And if you did any other macro recording or shortcuts editing using the NPP GUI, then even if you save shortcuts.xml, when you exit NPP, it will overwrite and lose those changes.)

    I took a fresh unzip of the portable NPP 7.5.8 64-bit, and edit the local shortcuts.xml (the one from the unzip directory, which is what the portable version will use) to include just the two Macros I quoted above, then save and exit. When I re-run that portable notepad++, it lists both the macros in the Macro menu. If I run Macro > RecordedMacro in a blank window, it adds the character C. If I then run Macro > DSC, it adds C then D. So that macro will run, when it’s in the shortcuts.xml exactly as I quoted.

  • Thanks anyway, but this way over my head. I’m just going to have to find something that does work with macros properly. It’s a shame, really - NPP works pretty well for everything else I need.

  • What you quoted wouldn’t have worked as quoted. My post did two things: it explained how to properly quote it, and it exactly quoted what should be in the shortcuts.xml file in order to accomplish something.

    If there’s something you don’t understand, feel free to ask. If I’m being unclear, ask for clarification.

    Notepad++ does do macros, and it does them well. Since it’s not working for you, we’re trying to help you figure out what you’re doing wrong (and if we are able to prove it’s actually a problem with Notepad++ itself, we’ll be able to help by submitting a bug report). But you have to be willing to help us help you.

    You may feel free to choose a different editor… But blaming it on the editor will probably hurt you in the long run, because you’ll get in the habit of not figuring something out and changing editors … possibly even until you’re out of editor choices. (it will also hurt others, because if there is a true bug in Notepad++, it’s not been proven yet, so it will come back and bite others until there’s a user who is willing to go through the back-and-forth to figure out what’s going wrong.)

  • Did you hand-write the code I saw in your message? I didn’t - I used the start/stop recording function, then went and named the macro and gave it a keystroke.

    I’m not much on XML programming, unfortunately. Oh and the dashes was NPP’s doing - I copied the code then pasted it into NPP, and it added the dashes.

  • The lines

        <Macro name="RecordedMacro" Ctrl="no" Alt="no" Shift="no" Key="0">
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" />

    were recorded by me some time ago.

    I then copied the Macro you had pasted earlier, cleaned out the smart-quotes into real quotes, and removed the dashes, then pasted them into my shortcuts.xml. I then copied the <Action ...> line from my macro into the beginning and end of yours. So my bigger macro is identical to what I assume your macro really is, except I added in the two lines that type a character. Those two lines will thus prove whether or not your macro is really running.

    You can copy the text from the <Macros> ... </Macros> in my example above (the last example, “try something like:”), paste them to completely replace that same section in your %AppData%\Notepad++\shortcuts.xml, save the file, exit NPP, reload NPP. Then start a new window, and try running “RecordedMacro”, then try running “DSC”. The first should insert a C. The second should insert a C and D, so the blank file should now contain CCD.

    For the dashes:

    • Why were you pasting into NPP: what were you using to read the shortcuts.xml to make sure the macro was recorded, if not NPP directly?

    • I’ve never seen NPP add dashes to something pasted into NPP. I’m curious whether you’ve got a strange plugin loaded: menu ? > Debug Info > Copy info to clipboard and pasting it here would let us know exactly what setup you’re using.

  • Hallo Michael,
    You must not use Notepad++ to edit your shortcuts.xml. I stop N++ and use editpad lite which is adequate for use of inspecting and altering . The file I edit is at C:\Documents and Settings\Tony\Application Data\Notepad++\shortcuts.xml
    What I do is record a macro and run it to check. If it needs altering I either record it again or I have a go at editing it. One can add macros together by editing.

  • @Tony-Moody,

    You must not …

    That’s not strictly true. “You must be careful if you …” would be the better way of phrasing that.

    C:\Documents and Settings\<username>\Application Data\Notepad++\shortcuts.xml

    And I can now identify that you’re on an older Windows, such as Win2k or WinXP. For more on the %AppData%, see our FAQ on the topic – which includes an explanation for how the simplest way to access folders in the user-app-data hierarchy is by %AppData%\FolderName, so you don’t have to know which file hierarchy your system uses.

    What I do is record a macro and run it to check. If it needs altering I either record it again or I have a go at editing it. One can add macros together by editing.

    Yep, those are good, solid advice.

    Editing Configuration Files

    As it says in NpWiki++: Configuration Files, “Because Notepad++ updates some of its configuration files on normal program termination, manual editing of a Notepad++ configuration file requires both specific procedures and good knowledge of the files’ layout. It is strongly advised to read about how to edit configuration files and the knowledge base for file layouts.”

    The editing configuration files page claims you have to mark the files as read-only, but that’s not technically accurate, either.

    Notepad++ will overwrite the shortcuts.xml file when it exits… but only if you’ve recorded a new Macro, or if you’ve used the Settings > Shortcut Mapper or Macro > Modify Shortcut / Delete Macro…. (There may be one or two other circumstances that I haven’t thought of, but if there are, they seem to be more rare.)

    A sequence that has always worked for me, every time, for editing the shortcuts.xml from within Notepad++:

    1. Close all active instances of Notepad++.
      • This will make sure Notepad++ saves any changes it needs to save into shortcuts.xml.
    2. Open one instance of Notepad++.
      • Do nothing else regarding Notepad++, other than what’s described in these steps, while following these instructions.
      • Do not open another instance.
      • Do not change GUI settings, especially the Shortcut Mapper… or Modify Shortcut / Delete Macro….
    3. Open %AppData%\Notepad++\shortcuts.xml using that one instance of Notepad++
      • if you’re in a portable installation, open the local shortcuts.xml instead
    4. Make your edits to shortcuts.xml using that one Notepad++, without opening any other instances.
    5. Save shortcuts.xml
    6. Close that one instance of Notepad++.
    7. When you open Notepad++ again, the changes you made should take effect
      • if you handcrafted a new macro, or edited an existing one, it should be available in the Macro menu.
      • You can also re-load shortcuts.xml to make sure the changes are still in place; they should be (they are for me).
    8. If shortcuts.xml is open, either
      1. Close shortcuts.xml again, so that you don’t expect it to be editable this time,
      2. if you do want to safely edit shortcuts.xml more, and haven’t done anything else with Notepad++, you’re effectively back at step #3 right now, and can continue the sequence from there

Log in to reply