Insert Text With Unique Incremental Value
-
I want to find a way to insert some type of unique value into a document (which I will use at the end of the NPP text file to identify new articles I write) upon command
My goal is to insert some sort of unique incremental value so that all documents have a unique ID, possibly by using a macro to execute with a function to insert the value and increment it each time I insert the characters
The value could be numeric (possible an integer), a string value of around 10 or more characters, or even a combination of letters and numbers. The unique value could even pull from my Windows 10 system based upon the time and date
In some languages I would use something like UniqueID to generate in the yymmddhhss or even a yyMMddhhmmssMs format. If I was in a database (and I am NOT wanting that headache) I would generate an autoincrement or even a GUID, and have seen the following used in SQL:
DateTimediff(Left([Date],10),‘2000-01-01’,‘days’)
I have also seen some languages execute the following to generate the irst 14 characters based on the current time stamp in format YYYYMMDDHHMMSS, followed by an underscore and a random set of four alphanumeric characters:
date=$(date +%Y%m%d%H%M%S)
rand=$(cat /dev/urandom | tr -cd [:alnum:] | head -c 4)
ID=$date"_"$randThis generates a text string with the output: 20101230193212_pOiF
This could be probably be done by a macro (and I am good at those thru my Excel MOS skills) and that would be perfect for me. I have looked thru the NPP Wiki and every website I can think of for the last four days, and I am perplexed as to how to do this. I also did some Google searches looking for a solution, but thus far have had no luck
Could someone point me in the right direction? If there is a total solution, I’m glad to implement, but I am also happy to learn this as a new NPP skill for me
Thanks for the helpMichael
-
@MickardEMT said:
Could someone point me in the right direction? If there is a total solution, I’m glad to implement, but I am also happy to learn this as a new NPP skill for me
I would probably recommend using the PythonScript plugin for Notepad++; it can be used to automate various tasks inside Notepad++, including generating text and entering text into the active editor window, using the Python programming language. (There’s a similar plugin LuaScript which uses Lua programming language for the syntax, and I think there’s a jN Notepad++ Plugin, which allows automating of Notepad++ with Javascript). With any of these, you should be able to make a program to generate random or date-based text, and append it to the end of the active editor window.
If you search through this forum for recent posts on “timestamp”, you can probably even find examples of PythonScript code that will add a timestamp to the existing file.
Once you’ve got a starting point, if you need help, feel free to ask.
-
You need to do some scripting, e.g. Pythonscript’ing or LuaScript’ing. You could certainly do your timestamp + random thingy with that, and bind the script to run on file-save…basically do whatever you need.
-
Peter
Thank you. Right after I posted this I decided on a different Google search string and started finding this in Python. I think I excluded them because I never needed to attempt Python before (I work in statistical modeling in healthcare) but this is a new day
Thank You! I am headed to find some Python love LOL
Michael
-
@MickardEMT said:
Thank You! I am headed to find some Python love LOL
In case you haven’t found it yet, this post catalogs a couple of pages with example PythonScript code to insert a date-based stamp into your file. It would be pretty easy to modify for random-based instead.
Again, good luck.