I think I have come up with a proof of concept solution, but it is a little convoluted and (currently) causes a crash in Notepad++ so it probably isn't viable just yet. I thought I would post it anyway as others might be looking at solving similar problems.
The beta plugin Notepad++ Python Script adds supports for scripting in Notepad++ including hooking into existing Notepad++ notifications. The plugin includes a startup script that is always run as long as "ATSTARTUP" is selected in the plugin's configuration options.
- Launch a batch file from the legacy tool (it can be minimized at launch)
- Change command windows title to something known by Notepad++ and unique (the file name will probably do) so that it can be killed later on
- Launch Notepad++ from the batch file with the file as a command line argument
- Automatically register a python function as a callback on the FILEBEFORECLOSE notification at startup
- When a file is closed use the filename to reconstruct the window title of the command prompt and use that to kill it.
This successfully causes the command window to close but then Notepad++ locks up. I think this is an issue with the python plugin. It seems that calling console.run() from a notification callback causes problems. I know the command is well formated because it works without a crash when run from a user triggered script. This script runs every time a file is closed and it causes Notepad++ to hang so I don't recommend you use this solution in its current state
Command to run from legacy tool:
start /min nppblock.bat
notepadpp_blocker.bat:
@echo off FOR %%i IN (%1) DO ( set filename=%~nx1 ) title=nppblock_%filename% echo Waiting for %filename% to be closed in Notepad++ "C:\Program Files (x86)\Notepad++\notepad++.exe" %1 pause
Added to C:\Program Files (x86)\Notepad++\plugins\PythonScript\scripts\startup.py:
import os.path def fileBeforeCloseCallback(args): filename = os.path.basename(notepad.getBufferFilename(args["bufferID"])); killcmd = 'taskkill /f /fi "WINDOWTITLE eq nppblock_' + filename + '" /im cmd.exe' console.run(killcmd) notepad.callback(fileBeforeCloseCallback, [NOTIFICATION.FILEBEFORECLOSE])