Macro acting out
-
What am I doing wrong? Here’s what I do:
- Open a txt file
- Macro > Start recording
- Encoding > Convert to UTF with BOM
- File > Save
- File > Close
- 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!
-
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 integer0 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="&New"/> <Item id="41002" name="&Open"/> <Item id="41019" name="Explorer"/> <Item id="41020" name="cmd"/> <Item id="41003" name="Close"/> <Item id="41004" name="C&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="&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 -
Thank you Claudia, it works! Now I can write my macros instead of ‘recording’ them… great! Problem solved :)
-
@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 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.
-