NPPexec Tidy won't open html file.
-
I used to have an NPPexec macro which ran an external Tidy on the current file and displayed Tidy messages in the console. My computer crashed so hard I couldn’t restore from an image, so I did a clean Win11 install. I’m trying to replace that macro.
I dug up a few versions on the Web but they all have the same problem. Here’s what I have now:// 1. Temporarily save the current document state NPP_SAVE // 2. Run Tidy silently, format the active file, and overwrite it "C:\Program Files (x86)\tidy-5.4.0\bin\tidy.exe" -modify -indent --indent-spaces 2 --wrap 120 "$(FULL_CURRENT_PATH)" // 3. Force Notepad++ to reload the updated text cleanly NPP_OPEN "$(FULL_CURRENT_PATH) // 4. to see the formatted changes NPP_RELOADWhich results in:
NPP_SAVE: C:\Temporary\BitToggle.html "C:\Program Files (x86)\tidy-5.4.0\bin\tidy.exe" -modify -indent --indent-spaces 2 --wrap 120 "C:\Temporary\BitToggle.html" Process started (PID=33372) >>> Error: Can't open "C:\Temporary\BitToggle.html" About HTML Tidy: https://github.com/htacg/tidy-html5 Bug reports and comments: https://github.com/htacg/tidy-html5/issues Official mailing list: https://lists.w3.org/Archives/Public/public-htacg/ Latest HTML specification: http://dev.w3.org/html5/spec-author-view/ Validate your HTML documents: http://validator.w3.org/nu/ Lobby your company to join the W3C: http://www.w3.org/Consortium Do you speak a language other than English, or a different variant of English? Consider helping us to localize HTML Tidy. For details please see https://github.com/htacg/tidy-html5/blob/master/README/LOCALIZE.md <<< Process finished (PID=33372). (Exit code 2) NPP_OPEN: "C:\Temporary\BitToggle.html NPP_RELOAD ; about to start a child process: "NPP_RELOAD" CreateProcess() failed with error code 2: The system cannot find the file specified. ================ READY ================Of course the freakin’ file exists, I’m editing it in Notepad++ x86. WTF?
-
Which results in:
NPP_SAVE: C:\Temporary\BitToggle.html "C:\Program Files (x86)\tidy-5.4.0\bin\tidy.exe" -modify -indent --indent-spaces 2 --wrap 120 "C:\Temporary\BitToggle.html" Process started (PID=33372) >>> Error: Can't open "C:\Temporary\BitToggle.html"I don’t know why you got that. If you open cmd.exe (not in Notepad++) and send
"C:\Program Files (x86)\tidy-5.4.0\bin\tidy.exe" -modify -indent --indent-spaces 2 --wrap 120 "C:\Temporary\BitToggle.html", does it give the same error? Because if it gives an error there, then there is something wrong in the tidy syntax; but if that command doesn’t given an error in cmd.exe, then we need to try to figure out what’s actually different between the two.Assuming the command works when BitToggle.html is not open in Notepad++ and you run that command from the cmd.exe command line, my initial guess is that
tidy.exewants an exclusive lock on the file, and if it’s open in Notepad++, then it can’t get that lock. But that’s just a guess. So the first thing you need to do is confirm whether or not the command works when it doesn’t involve Notepad++ or NppExec.NPP_OPEN: "C:\Temporary\BitToggle.html NPP_RELOAD ; about to start a child process: "NPP_RELOAD" CreateProcess() failed with error code 2: The system cannot find the file specified.That one’s easier: there’s a missing endquote. In your script, you showed:
// 1. Temporarily save the current document state NPP_SAVE // 2. Run Tidy silently, format the active file, and overwrite it "C:\Program Files (x86)\tidy-5.4.0\bin\tidy.exe" -modify -indent --indent-spaces 2 --wrap 120 "$(FULL_CURRENT_PATH)" // 3. Force Notepad++ to reload the updated text cleanly NPP_OPEN "$(FULL_CURRENT_PATH) // 4. to see the formatted changes NPP_RELOADDo you notice on the
NPP_OPENline? There is no closing quote after the$(FULL_CURRENT_PATH), and command interpreters do strange things with unclosed quotes. So add that endquote.NPP_RELOADDid you get this from AI? Because NPP_RELOAD is not found anywhere in the NppExec repository. I think your AI may have hallucinated that.
If I use Plugins > NppExec > Help/Manual and go to section 4. Advanced Usage > 4.6. Using external tools > 4.6.15. Triggering certain actions while saving a file (*), about halfway down, I find
npp_sendmsg NPPM_RELOADFILE 0 "$(FULL_CURRENT_PATH)"as the syntax for reloading a file. (*: no, I didn’t find it that way; I searched the manual forreload, and that’s just the section that had it.)So, assuming the
tidy.exesyntax is correct, then the script should be:// 1. Temporarily save the current document state NPP_SAVE // 2. Run Tidy silently, format the active file, and overwrite it "C:\Program Files (x86)\tidy-5.4.0\bin\tidy.exe" -modify -indent --indent-spaces 2 --wrap 120 "$(FULL_CURRENT_PATH)" // 3. Force Notepad++ to reload the updated text cleanly NPP_OPEN "$(FULL_CURRENT_PATH)" // 4. to see the formatted changes NPP_SENDMSG NPPM_RELOADFILE 0 "$(FULL_CURRENT_PATH)"
I just went to the https://binaries.html-tidy.org/ and unzipped tidy 5.4 (I put it in
c:\usr\local\apps\tidy-5.4.0\), and created aC:\Temporary\BitToggle.htmlwith some HTML in it. When I ran the script I showed (but with my path to tidy.exe rather than yours), it worked for me:NPP_SAVE: c:\Temporary\BitToggle.html "C:\usr\local\apps\tidy-5.4.0\tidy.exe" -modify -indent --indent-spaces 2 --wrap 120 "c:\Temporary\BitToggle.html" Process started (PID=20256) >>> Info: Document content looks like HTML5 No warnings or errors were found. About HTML Tidy: https://github.com/htacg/tidy-html5 Bug reports and comments: https://github.com/htacg/tidy-html5/issues Official mailing list: https://lists.w3.org/Archives/Public/public-htacg/ Latest HTML specification: http://dev.w3.org/html5/spec-author-view/ Validate your HTML documents: http://validator.w3.org/nu/ Lobby your company to join the W3C: http://www.w3.org/Consortium Do you speak a language other than English, or a different variant of English? Consider helping us to localize HTML Tidy. For details please see https://github.com/htacg/tidy-html5/blob/master/README/LOCALIZE.md <<< Process finished (PID=20256). (Exit code 0) NPP_OPEN: c:\Temporary\BitToggle.html NPP_SENDMSG: NPPM_RELOADFILE 0 "$(FULL_CURRENT_PATH)" ================ READY ================So that works for me. Given that it worked from NppExec with it open in Notepad++ for me, I don’t know why you got the first error when you ran the script…
-
Thanks, your script works perfectly.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login