Let's imagine we want to use NppExec for file backup, and want NppExec's Console to be automatically shown at the beginning of the file backup and automatically hidden at the end.
Thus, the Console will be just an informational window that is shown to reflect the progress of certain operations and then is hidden.
The file backup operations may be as simple as that:
set local backupDir = $(SYS.USERPROFILE)\OneDrive\ // the backup directory npp_save // saving the current file cmd /C copy /B /Y "$(FULL_CURRENT_PATH)" "$(backupDir)" // backing the current file up
By default, when NppExec executes a script, the Console is automatically shown, unless npp_console ? is explicitly specified at the very beginning of the script. Then, at the end of the script, a visible Console remains visible.
For the purpose of auto-hiding the Console at the end of the script, we need to alter the default behavior. We need to use the npp_console command with the specific parameters:
npp_console local on
This command has the following effects: 1. If the Console is hidden, it is shown. 2. As this command is local, the previous state of the Console (before the script) is restored at the end of the script. I.e. if the Console was hidden before the script, it is shown during the script and then becomes hidden at the end of the script. This is the desired "Auto-hide" behavior. So, this is the exact command we want at the very beginning of our script.
(Note: With this command, if the Console was shown before the script, it remains shown after the script. If you want the Console to be always hidden at the end of the script, use npp_console off at the end of the script).
As the Console will be auto-hidden, we may need some pause to read the Console's output while it is visible:
sleep 2000 // waiting for 2 seconds
Also, we may want to preserve the keyboard focus in the editing window rather than having the focus in the Console while it is visible:
npp_setfocus sci // setting the focus to the Scintilla's editing window
Finally, it is a good idea to disable the output to the Console while the auxiliary commands are executed:
npp_console local - // disabling the output to the Console
So, here is the full script:
// 1. Begin: Showing the Console in its auto-hiding mode npp_console local on // showing the Console if it is hidden // 2. Operation: File backup npp_console local - // disabling the output to the Console set local backupDir = $(SYS.USERPROFILE)\OneDrive\ // the backup directory npp_setfocus sci // setting the focus to the Scintilla's editing window npp_console local + // enabling the output to the Console npp_save // saving the current file cmd /C copy /B /Y "$(FULL_CURRENT_PATH)" "$(backupDir)" // backing the current file up // 3. End: Delay the Console auto-hiding npp_console local - // disabling the output to the Console if $(IS_CONSOLE0) != 1 then // was Console not visible initially? sleep 2000 // waiting for 2 seconds endif