-- -- Timestamp.lua: A NoteCase Pro LUA script by Daniel Hertrich, http://www.hermocom.com -- -- This script's author, Daniel Hertrich, hereby waives all copyright -- and related or neighboring rights to this script, pursuant to the -- Creative Commons CC0 Universal relinquishment of rights found at -- http://creativecommons.org/publicdomain/zero/1.0/ -- -- Purpose: Create a conveniently formatted time stamp inside a note at the current cursor position -- -- Usage: Place the cursor where you want the time stamp to be inserted into the note, -- then start this script. In the appearing dialog you may enter a title, which -- will be printed on the right of the time stamp in bold font. -- Hit Esc or Enter on the empty title dialog to not use any title. -- -- For convenient usage, assign a shortcut to this script. -- Adjust the format of the time stamp to your needs (see table below for available date/time tags): strDateFormat = "%Y-%m-%d" strTimeFormat = "%H:%M" -- %a abbreviated weekday name (e.g., Wed) -- %A full weekday name (e.g., Wednesday) -- %b abbreviated month name (e.g., Sep) -- %B full month name (e.g., September) -- %c date and time (e.g., 09/16/98 23:48:10) -- %d day of the month (16) [01-31] -- %H hour, using a 24-hour clock (23) [00-23] -- %I hour, using a 12-hour clock (11) [01-12] -- %M minute (48) [00-59] -- %m month (09) [01-12] -- %p either "am" or "pm" (pm) -- %S second (10) [00-61] -- %w weekday (3) [0-6 = Sunday-Saturday] -- %x date (e.g., 09/16/98) -- %X time (e.g., 23:48:10) -- %Y full year (1998) -- %y two-digit year (98) [00-99] -- %% the character `%´ function create_timestamp(strTitle, nFirstEntry) dateNow = os.date ("*t") -- Nc_GUI_MessageBox("Date year: " .. dateNow.year .. ", month: " .. dateNow.month .. ", day: " .. dateNow.day .. "\nHour: " .. dateNow.hour .. ", Minute: " .. dateNow.min) nDateNow = os.time{year=dateNow.year, month=dateNow.month,day=dateNow.day, hour=dateNow.hour, min=dateNow.min, sec=dateNow.sec,isdst=dateNow.isdst} strDate = os.date (strDateFormat, nDateNow) strTime = os.date (strTimeFormat, nDateNow) strTimeStamp = "___________________________________________________
" .. strDate .. " " .. strTime .. " " .. strTitle .. "

" if nFirstEntry == 1 then return strTimeStamp else return "

" .. strTimeStamp end end -- get info on the currently active document/note nDocID = Nc_Doc_ID_GetCur() strCurNodeID = Nc_Note_ID_GetCur(nDocID) if strCurNodeID == "" then Nc_GUI_MessageBox("Error: No node selected in the current document") return end strTitle = "" -- You may comment out the following line if you don't want to use titles on your timestamps: strTitle = Nc_GUI_InputDlg("Enter title:","") -- Generate the timestamp string strTimeStamp = create_timestamp(strTitle, 0) -- determine current cursor position nFrom, nTo = Nc_Note_SelectionRange_Get(nDocID, strCurNodeID) -- insert timestamp at cursor position. If text was selected, replace selected text with timestamp nLength = Nc_Note_Content_Set(nDocID, strCurNodeID, strTimeStamp, 1, nFrom, nTo) -- place cursor behind the new time stamp, so you can continue to write instantly Nc_Note_SelectionRange_Set( nDocID, strCurNodeID, nTo+nLength, nTo+nLength)