3.7. NppExec's script

NppExec's script is a set of NppExec's commands. NppExec's command can be an internal command such as "cls", "npp_save", "npe_debuglog" etc. or it can be a (path)name of an executable such as "cmd", "calc", "C:\tools\tcc\tcc.exe" etc. Each command, depending on its meaning, can have one or more parameters. For example:

INPUTBOX "Input something:" : something
NPP_EXEC "script name" "param 1" "param 2"
cmd /c copy /?
"C:\tools\tcc\tcc.exe" -run "$(FULL_CURRENT_PATH)"

and so on. You can use "//" to comment an entire line or right part of a line (after "//"):

// this is a comment
ECHO You'll see this // but not this (comment)

You can create and save NppExec's scripts using the "Execute NppExec Script..." dialog [3.6]. However, NppExec's script can also be located in a text file. I.e. you can create a text file which contains some NppExec's commands (one command per one line) and then execute this file (commands from this file) in NppExec. Such text file can be an ANSI file for ANSI version of NppExec and can be an ANSI or Unicode (UCS-2 LE/UCS-2 BE/UTF-8) file for Unicode version of NppExec. Note that Unicode text file must contain leading "BOM" bytes to be recognized by Unicode version of NppExec (by default, these bytes are present - until you force saving without "BOM"). To execute NppExec's script from a text file, use the "npp_exec" command. This command allows to execute commands from a previously saved (internal) script or from an (external) text file.

As you can store your NppExec's script in a text file, you can edit such file directly in Notepad++ and execute it with the following command(s):

NPP_SAVE  // save current file (NppExec's script)...
NPP_EXEC "$(FULL_CURRENT_PATH)"  // ...and execute it

With the Console Commands History enabled, you can type this command:

NPP_EXEC "$(FULL_CURRENT_PATH)"

in NppExec's Console once, then use the Arrow Up key to repeat this command. However, be sure to save current file (with Ctrl+S) before executing it.

To create a menu item for NppExec's script, use NppExec's Advanced Options dialog. Then a shortcut key can be assigned to it:

  1. Create a menu item for the script using Plugins -> NppExec -> Advanced options (select a script in the "Associated script" drop-down list, specify its menu item name - by default it's the same as the script name - and press the "Add/Modify" button).
  2. Restart Notepad++ to get this new menu item.
  3. Assign a shortcut key to this new menu item using Notepad++'es Settings -> Shortcut Mapper -> Plugin commands (you'll find the menu item there).

NppExec stores your scripts in Notepad++'es "$(PLUGINS_CONFIG_DIR)" folder. The "npes_saved.txt" file stores all the scripts except the temporary one which is stored inside "npes_temp.txt".

NppExec's script syntax. General notes:

 

See also: "Execute NppExec Script..." [3.6]; Run-time parameters [4.3].