Automate Notepad++ new doc creation
-
I would like to find a way to automate Notepad++ in this way. I want to create a tab with text that has a type of language set. The text will be provided dynamically. I am thinking via the command line, or something. I guess I could do this via some type of script. I want the Notepad++ tab to similar to the default new tab, the difference being the language of choice and the dynamically provided text. To be clear, If I decide to not save it as a file it will just be deleted. I also would like to avoid using the clipboard. Thanks for any ideas or help.
-
@Chris-Johnston If you already are using the command line then write a batch file that first creates a blank file and then opens notepad on that file.
The file extension plus possibly magic numbers in the file header can be used to set the language notepad++ will be using for that file.
Your batch file can also pre-fill the file. For example, I have a batch file named np.bat that I use to launch/open Notepad++. Among other things, np.bat checks to see if the file has a .bat or .cmd file extension and if so will generate a default batch file that has a stuff I always have in my batch files. np.bat then launches notepad.exe with that file. Notepad++ sees the .bat extension and will use the “Batch” language for the file.
By “magic numbers” I mean the beginning of file or BOF marks. If I want my new .txt files to have a Unicode UTF-8 BOF then I would first create a template text file with the UTF-8 BOF. If np.bat sees that I want to create a new .txt file then it would copy from the template to the new file name and then launch Notepad++.
-
It seems a little odd to create and dynamically populate a document in Notepad++ and not save it as a file to disk. But if that’s what you want…
if the text you want to create is short (ie, short enough to create from a command line, which has a limited number of characters, you could use command line options:
notepad++.exe -lhtml -qSpeed3 -qt="Text to type" REM . . . . . . ^^^^ -- whatever language you want; see usermanual
But Windows (not Notepad++) limits the number of characters that can be passed to an application via the command line. So if you want to dynamically create a file with more than a few hundred characters, the command-line isn’t going to meet your needs.
Alternatively, the PythonScript plugin allows you to fully automate Notepad++ from a script run with the plugin, so if you know Python, you can install that plugin, then use that script to create a new file (
notepad.new()
) and set the current language (notepad.setCurrentLang(LANGTYPE.HTML)
or whichever language) and then add text programmatically (editor.addText("Text Goes Here")
)But why not just use your dynamic creation script to write to a file with a reasonable extension and save it in a reasonable place, and then call notepad++ to open that file. If you end up not wanting to keep the file, just delete it. That’s really the easiest.
-
@Chris-Johnston said in Automate Notepad++ new doc creation:
I would like to find a way to automate Notepad++ in this way. I want to create a tab with text that has a type of language set. The text will be provided dynamically. I am thinking via the command line, or something. I guess I could do this via some type of script. I want the Notepad++ tab to similar to the default new tab, the difference being the language of choice and the dynamically provided text. To be clear, If I decide to not save it as a file it will just be deleted. I also would like to avoid using the clipboard. Thanks for any ideas or help.
I think it matters how the text is being provided, roughly how large it is, and what skills and time are available to dedicate to the problem. I don’t know of anything intrinsic to Notepad++ that will help much with this.
Also, it’s unclear (to me) whether you want to launch Notepad++ with the new tab, or whether Notepad++ will already be open and you want to create a Notepad++ command that will open a new tab pre-filled with information dynamically drawn from some other source.
The command problem is definitely one for a plugin, which you would have to write to access the specific data source you need. Folks who know Python seem to like the Python scripting plug-in, so if you know how to access your data through Python, that might be the way to go.
If you’re wanting to launch Notepad++, my guess is that you want a scripting solution like AutoIt. I’ve never used that program, but it sounds like it could do what you need — after climbing a substantial learning curve.
-
@mkupper Thanks that is helpful. You raise another question now.
-
@PeterJones Thanks super helpful, just was I was looking for. I do know something about about Python think that will be the way to go. However, I am glad to know the command from cl. Wow!
-
@Coises Hi, and thanks for the great reply. I am going to explore this Python scripting plug-in idea, as said above. Funny enough, I did first post a message on the AutoIt forum for ideas about this. I did not get any responces. However I am still waiting. After that I had planned on getting creative with AutoIt because I know how to do it. Although, you wonderful people hear have given me the some super ideas. Thanks so much!
https://www.autoitscript.com/forum/topic/210204-automate-notepad-new-doc-creation-moved/
-
@Chris-Johnston In reading https://www.autoitscript.com/forum/topic/210204-automate-notepad-new-doc-creation-moved/ it appears that in Notepad++ you want
Settings / Preferences / New Document (on left sidebar) / Default language to be
AutoIt
.Notepad++ can already do that. What Notepad++ does not seem to have baked in at present is a default blank document template. It’s not clear though
if filling in the new tab with stuff related to a generic .au3 file is useful or essential to you. Any of what people have already suggested here will do for filling in the default new-document but it’s also possible a plugin exists that can do this.