SaveAs as last command in macro; possible?



  • Title says it all. LOL. Just kidding.

    So I have a macro that does a big replace on a log file.
    I want to make sure I don’t overwrite the original log file, so I had the idea to prompt myself with a Save As after my macro does its work. So it would be the last command in the macro, and things would end with the user (me) looking at a Save As prompt box.

    Doing some testing, I see that I can record a macro doing a Save As (only!, not my replace stuff too), but playing it back does nothing.

    If I save the macro, what gets put in shortcuts.xml is:

            <Macro name="saveas_test" Ctrl="no" Alt="no" Shift="no" Key="0">
                <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
                <Action type="2" message="0" wParam="45001" lParam="0" sParam="" />
            </Macro>
    
    

    42024 seems to be a “trim trailing” operation (that I didn’t ask for – could this be influenced by the editorconfig plugin??)

    45001 seems to be a “windows line ending” command (ok, now I’m more convinced editorconfig is having an effect)

    In spite of my findings, is there any way to achieve this functionality, specifically, Save As as last command in a macro?

    Sure, could turn to scripting…



  • @Alan-Kilborn said in SaveAs as last command in macro; possible?:

    Save As as last command in a macro?

    Save As is NPP Message 41008, but appears to be one of the many menu commands that cannot be recorded, but can be played back. If you manually insert

            <Action type="2" message="0" wParam="41008" lParam="0" sParam="" />
    

    and then reload, your macro should now bring up the Save As dialog



  • Addendum:

    My guess as to the reason that Save As isn’t recordable: because half the users would want it to record the Save As including the filename, and will be upset if it doesn’t save the name in the macro; and the other half would yell and scream if the macro did record the filename, because obviously they wanted a different filename every time Save As is run. And there’s enough of that arguing for other issues, so the developers just disabled recording for Save As, upsetting the third half of the users. ;-)

    Well, okay, the real reason is they probably just forgot to put it in the list of recordable messages. But that might be a reason why they haven’t added it when doing other fixes of which actions are recordable.



  • Thanks @PeterJones ; worked like a charm.
    One day I’ll think to just try the manual add, instead of relying on the recorder (I’m certainly not afraid to hand-edit shortcuts.xml).



  • @Alan-Kilborn ,

    The end of NppCommands.cpp has the list of IDM_ entries (ie, the menu commands) that are macro-recordable. So any not listed there are not.


Log in to reply