batch script run in place
-
I can run my script in place, but is there a way I can save the file when I (before) I run (ctrl+s)
-
You didn’t say, but for the sake of my answer, I will assume when you say “I can run my script in place”, you mean “I use the Run > Run menu command to run
cmd /c "$(FILE_NAME)"
(or similar) to run the active file using its default assocation” or maybe “I have saved that Run > Run command into the Run menu, and maybe have a keyboard shortcut for it”. If I have misinterpreted your statement, you will have to clarify with much more detail.The Notepad++ macro system can record certain actions then play them back. Unfortunately, as explained in our FAQ: Automating Notepad++, certain commands – like those from plugins, and the user-defined commands that you save in the Run menu (or even calls to other macros) – cannot be recorded . However, that same FAQ explains that you can trick the macro system to run non-recordable commands by manually editing the macro, as described in that second post. So you could manually create a macro that runs the File > Save then runs the dynamic menuCmdID assigned to your Run command or Plugin command, that you can find using UISpy!
Alternatively, the NppExec plugin is designed for being a “shell scripting” language for Notepad++, allowing running various N++ commands and various filesystem commands. I have saved the following NppExec script as
RunMyself
, which saves the active file, changes to that file’s directory, and runs that file:NPP_SAVE cd "$(CURRENT_DIRECTORY)" cmd /c "$(FILE_NAME)"
… and I use Shortcut Mapper to set its keyboard shortcut to
F5
(and relegate the Run>Run command toCtrl+Shift+F5
, because I’d rather have the easiest shortcut be for the actions I use the most)You could do a similar script for the PythonScript plugin or other of the scripting plugins, but IMO, NppExec is best suited when you are trying to do just a sequence of actions that are too complex for Macros, but don’t have the logic or computational needs of a full programming language like Python.