Intercept a particular Notepad ++ instance
-
Hi, I need some advice. Let say we have two separate Notepad++ folder (portable):
A\notepad++.exe
(shortyly A)
B\notepad++.exe
(shortlby B)Both are run at the same time with
-multiInst
arguments. Step to reproduce:- run A
- run B << let say this NPP was the last active
- go to other window folder (or program)
- do sth like this
A\notepad++.exe -multiInst file.txt
(in console or through another program)
Our file will be open in B (not A) - it looks like due to recent activity on B. So my question is how can I intercept this situation? But without using any visual macro recorder, I need this in a more predictable way. I’ll just add that I can use Node.js or any other .exe if necessary (and of course inbuilt Windows tools.).
-
In step 4 I mean
A\notepad++.exe file.txt
(delegate file to proper opened instance). -
My experiments showed slightly different than you described: if in step #4 I use the
-multiInst
option again, it would add a third NPP window, but adding to the existing session from instance A. <edit> oh, right, that’s what you already corrected in your follow-on post; sorry </edit>If my third run of Notepad++ was without the
-multiInst
option, the command line would attach the new file to whichever instance of Notepad++ was most recently accessedI tried renaming the executables: since I was using one portable 787 and one portable 788, I ended up naming them
npp787.exe
andnpp788.exe
– but even with different executable names, the file would attach to whchever NPP instance was most recently used, rather than the instance of the executable specified. This is probably because both NPP instances register themselves the same with the Windows environment.In theory, if you could grab the hWnds for the individual Notepad++ instances, you could send a File Open (
NPPM_DOOPEN
) message to the right instance, rather than calling it with the executable.You might even be able to set up a PythonScript (or similar) notification handler that looks for an additional option after
-z
(and the-z
example from @Ekopalypse) when the file-opening notification is handled, and have that handler determine whether it is the right instance, or whether it should try to pass it off to a different instance of Notepad++. It would get complicated, but might be doable.(I am planning on having similar functionality in my perl module that remote-controls Notepad++ – see #27 and #32 – but it’s not implemented yet, because of the level of complexity I ran across while thinking about it, and I just haven’t found the right Round Tuit yet.)
-
Thx for some advice, I don’t have much knowledge about C ++ and windows API, that’s why I’m looking for a something already working. I have searched for some Node modules but haven’t done the tests yet.
I correct in second post that in step 4 I don’t want use
-multiInst
(can’t edit here after some time!!!).Such selectting of the program dependent on the last one recently used (regardless of .exe) is the fault of Notepad++ or rather the default Windows behavior? I wonder if it could not be fixed somehow on the Notepad ++ side.
In general, I also wonder if we can run in NPP a server (with a certain port) through plugin and send some tasks to it (from outside) to control its behavior. This would solve many of these problems. Maybe PythonScript can do that? Any ready module would be advisable?
-
Btw, I will try check two Firefox portable if such situation also appear for them. If not then there will probably be something wrong with Notepad ++.
-
@ArkadiuszMichalski said in Intercept a particular Notepad ++ instance:
I will try check two Firefox portable if such situation also appear for them.
Not sure why that is relevant.
If not then there will probably be something wrong with Notepad ++.
I don’t think you’re going to get much support in there being something “wrong with Notepad++” in this regard.