* Export To Do Facts to Evernote

Writing and using plugins for Version 5 and above.
Post Reply
User avatar
Posts: 71
Joined: 03 Apr 2018 14:02
Family Historian: V6.2

Export To Do Facts to Evernote

Post by laz_gen » 14 May 2019 19:25

The ongoing discussions about To Do notes and Research Planners has made me reconsider how I was organising my own To Do's.

I create To Do facts to remind myself of records that need my attention. I have a custom query that searches for these facts and produces a report and have been saving these reports as a note in Evernote. I also add the individuals to a Named List but it doesn't seem possible to manipulate a Named List from a plugin so I thought I would try an alternative approach - a better (quicker) way of collecting together my To Do facts and adding them to an Evernote note.

The following is a plugin I have put together to automate the task. It searches for the facts, collects them in a table then exports them to a text file that gets stored in Evernote's default import folder. Evernote constantly scans that folder and automatically creates a note with any new file it finds.

There are probably better ways to achieve the same result and maybe further enhancements that could be added but as a bare minimum, it works for me.

All comments welcome.

Code: Select all

@Title: Search for and Export To Do facts
@Author: Robin Lasbury
@Version:	1.0
@LastUpdated:	14 May 2019
@Search for To Do facts and export the results to a text file in the default Evernote import folder, 
allowing Evernote to automatically create a note with the contents.

local ptrIndi = fhNewItemPtr()
local ptrFact = fhNewItemPtr()
local ptrRIN  = fhNewItemPtr()
local ptrName = fhNewItemPtr()
local ptrToDo = fhNewItemPtr()
local ptrNote = fhNewItemPtr()
local strRIN
local strName
local strToDo
local strNote
local tblFile = {}

function OpenFile(strFileName,strMode)
	local fileHandle, strError = io.open(strFileName,strMode)
	if not fileHandle then
		error("\n Unable to open file in \""..strMode.."\" mode. \n "..strFileName.." \n "..tostring(strError).." \n")
	return fileHandle
end -- function OpenFile
-- Save string to file --
function SaveStringToFile(strString,strFileName)
	local fileHandle = OpenFile(strFileName,"w")
end -- function SaveStringToFile

-- Loop through records --
function records(type)
    local pi = fhNewItemPtr()
    local p2 = fhNewItemPtr()
    return function ()
        if p2:IsNotNull() then return p2 end

-- Main program --
table.insert(tblFile, "==================================")			
table.insert(tblFile, "Note Created: " .. os.date("%c"))
table.insert(tblFile, "==================================")

for ptrIndi in records('INDI') do

	ptrFact = fhGetItemPtr(ptrIndi,'INDI._ATTR-TO_DO')

	if ptrFact:IsNotNull() then

		strRIN = fhGetRecordId(ptrIndi)

		strName = fhGetValueAsText(ptrName)

		strToDo = fhGetValueAsText(ptrToDo)

		strNote = fhGetValueAsText(ptrNote)

		table.insert(tblFile, "RIN: " .. strRIN)
		table.insert(tblFile, "Name: " .. strName) 
		table.insert(tblFile, "Category: " .. strToDo)
		table.insert(tblFile, "Note: " .. strNote)
		table.insert(tblFile, "==================================")


SaveStringToFile(table.concat(tblFile,"\n").."\n","D:\\Genealogy\\To Evernote\\Latest To Do.txt")

fhMessageBox('To Do Note exported to Evernote')

Post Reply