Skip to content

Instantly share code, notes, and snippets.

@emnavarro02
Last active July 12, 2022 06:27
Show Gist options
  • Save emnavarro02/52441a55fb75f90fad43cc65b4460035 to your computer and use it in GitHub Desktop.
Save emnavarro02/52441a55fb75f90fad43cc65b4460035 to your computer and use it in GitHub Desktop.
Insert timestamp on Notepad++

Insert Timestamp on Notepad++

This is a python-based plugin for inserting custom time/date on Notepad++ documents.

  1. Install the "Python Script" plugin. If you use the Notepad++ Plugin Manager, check where the PythonScript folder has been created (e.g., under %AppData% or %ProgramFiles%) If you prefer, install the PythonScript plugin manually. To do so, you can download the PythonScript plugin from http://npppythonscript.sourceforge.net/download.shtml.

  2. Save the script to the PythonScript\Scripts folder. In my case it was:

    "%ProgramFiles%\Notepad++\plugins\PythonScript\scripts\timestamp.py"
    
  3. Navigate to Menu bar > Plugins > Python Script > Configuration. Select "Machine Scripts", pick the "timestamp.py" script, then click "Add" and "OK".

    Note: depending on where you copied your script to, the script might be shown under "User Scripts"

  4. Assign a hot key (shortcut) by going to Menu bar > Settings > Shortcut Mapper > Plugin Commands > Timestamp, then click "Modify"

Source:

# https://ardamis.com/2014/03/09/adding-an-insert-datestamp-or-timestamp-macro-to-notepad-plus-plus/
# https://stackoverflow.com/questions/27950710/in-notepad-how-can-i-insert-the-current-date-and-time
#
#
# 1. Install "Python Script" MANUALLY
#
# Please note that you must download the Python Script plugin from http://npppythonscript.sourceforge.net/download.shtml
# because downloading it from the Plugin Manager in Notepad++ doesn't always work. (See the following thread for details.)
# https://stackoverflow.com/questions/26110973/emmet-notepad-unknown-exception
#
# 2. Save the script to :"%AppData%\Notepad++\plugins\Config\PythonScript\scripts\timestamp.py"
# 3. Navigate here: Menu bar -> Plugins -> Python Script -> Configuration and add the script
# 4. Assign a hot key by (shortcut) by going to Menu bar -> Settings -> Shortcut Mapper -> Plugin Commands -> Time, then click Modify
#
# Documentation about npp pythonscript editor:
# http://npppythonscript.sourceforge.net/docs/latest/scintilla.html#Editor.markerSetAlpha
import datetime
value = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")
editor.addText( value + ": ")
pos = editor.getCurrentPos()
editor.addText("\n------------------------------------------------------\n")
editor.gotoPos(pos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment