Creating and running macros
-
I have tried these steps - first creating a very simple macro, and it just doesn’t work at all. And I can’t find anything I’ve created in the directory that you gave. Where else could it be?
-
So following my instructions, if you ‘saved’ the macro and it successfully wrote the macro to 1 of 2 shortcuts.xml files, then by exiting and reloading Notepad++ you should see the ‘test’ macro listed under the Macro menu option. At this point I don’t care if the macro works, just if it exists in the menu option.
If the macro is not listed then the shortcuts.xml file is corrupt or you don’t have permisssions to edit that file. Regardless which is the problem I’d make a backup of that file (in both locations, see below), then attempt to edit the file first. If you are able to successfully edit it, then delete the file (you still have the backup). Start Notepad++, do your test macro, save it then exit, it should recreate the file. Then see which file it wrote to. Also see if the macro is listed when reloading Notepad++.
There are 2 locations that the shortcuts.xml file resides in, Notepad++ could be using either one, depending on how it was installed. Try the C:\Program Files\Notepad++ folder or C:\Program Files (x86)\Notepad++ folder. Depending on whether you installed the 32bit or 64bit Notepad++ program it could be in either of the 2 Program FIles folders (you can only install 64bit version if Windows is also 64bit).
Terry
-
I was able to find the XML file in the first directory you gave, and could view it - couldn’t tell whether it was corrupted. I am currently on 7.5.6 release, 64 bit, and my OS is Win10 Home 64 bit. I see that a new version has just come out - I can use CCleaner to remove my older version, but what installer should I be using? I do have 7zip
-
There should be 2 copies of the shortcuts.xml file, one in each location (c:\users and c:\program files…). Perhaps you are reading too much into my mention of a corrupted file, this is only a small possibility.
So far we haven’t established anything to be wrong, in saying that we haven’t made any progress. What I’m trying to do is break down the process into smaller steps and confirm each one before trying the next, that’s the only way we will solve your problem.
Can you give me the link to the video that showed you how to create a macro, I’d like to take a look before we mess around with your installation (installing a new version)?
In my previous email i asked whether you could save a macro, exit Notepad++ and then reload it, looking for the macro, what did you find?
Terry
-
I created the macro, saved it, exited NPP, and came back in - and the macro is still in the macro pulldown. I found the macro i created in the users directory version of shortcuts.xml, but not in the other one
There’s several YouTube videos on this topic here…https://www.youtube.com/results?search_query=creating+macros+in+notepad%2B%2B
-
So this is great progress. So now you have confirmed that you can successfully create a macro and that it saves correctly and loads back in Notepad++.
From your original question you say Search/Find, does that mean you aren’t trying to find text and replace with other text, just search for text?
If just searching for text, you probably need to know where those lines are. Bookmarking would seem to be what you need to help identify each occurance you are searching for. If this is what you intended then under the “FInd” menu option, you have several tabs, “Mark” is the one you want. This will identify the lines with a blue dot at left of the line containing the text. It will also highlight the text occurrences.
Terry
-
I’m just searching for text, and the ‘Search/Find’ command in the Search pulldown works fine. It’s just that I have a large list of strings to search, and I thought that if I could build a macro with that list, it would be a huge time saver, as it gets annoying to have to do a dozen or more terms over and over again
Actually this really doesn’t answer the original question at all- why doesn’t the macro execute? I would accept it if it executed and returned zero results, but in fact, it does absolutely nothing. Evidence suggests that whatever function is being used to execute a macro command is looking for it in the XML file that doesn’t have the user defined ones in it. Not much use for writing macros if this is the case as it will never, ever work.
-
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.
Terry
-
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"?>
-<NotepadPlus>
<InternalCommands/>
-<Macros>
-<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”/>
</Macro>
</Macros> -
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
```z <embed here> </embed> ```
Which gets rid of the need to indent. It will render like:
<embed here> </embed>
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.<NotepadPlus> <InternalCommands> ... redacted ... </InternalCommands> <Macros> <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> <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> <Macro name="RecordedMacro" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" /> </Macro> </Macros> ... redacted ... </NotepadPlus>
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 letterC
or not.If that works, then try inserting the
C
action at the beginning and end of your “DSC” macro, and see whether bothC
’s are typed (might want to change the second to aD
, to distinguish the two). Thus, try something like:<NotepadPlus> <InternalCommands/> <Macros> <Macro name="RecordedMacro" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" /> </Macro> <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" /> </Macro> </Macros> ... </NotepadPlus>
See whether the “RecordedMacro” properly does the
C
, and whether the “DSC” macro does theC
andD
.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 characterC
. If I then run Macro > DSC, it addsC
thenD
. 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" /> </Macro>
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. -
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++:- Close all active instances of Notepad++.
- This will make sure Notepad++ saves any changes it needs to save into
shortcuts.xml
.
- This will make sure Notepad++ saves any changes it needs to save into
- 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….
- Open
%AppData%\Notepad++\shortcuts.xml
using that one instance of Notepad++- if you’re in a portable installation, open the local
shortcuts.xml
instead
- if you’re in a portable installation, open the local
- Make your edits to
shortcuts.xml
using that one Notepad++, without opening any other instances. - Save
shortcuts.xml
- Close that one instance of Notepad++.
- 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).
- If
shortcuts.xml
is open, either- Close
shortcuts.xml
again, so that you don’t expect it to be editable this time,
or - 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
- Close
- Close all active instances of Notepad++.