Page 2 of 2

Re: Lua Script todo.txt

Posted: April 11th, 2012, 4:04 pm
by aidayong
an update to the todo.txt lua script. i have made some changes

1) display list of task mark as priority (.) eg. 2012-04-03 (A) get some sleep.
2) display the first seven task chronological
3) display task age in year or month or day (date difference between now and date task was add)
4) able to archive task as completed by leftdoubleclick
5) use string.format ('%02d') to add leading zero for number below than 10

test.lua

Code: Select all

function Initialize()

   sFileName 	= SELF:GetOption('FileName')
   sKeyword 	= SKIN:GetVariable('Keyword')
   sUserInput	= SKIN:GetVariable('UserInput')
   
 end -->Initialize

function Update()
	tNum = {} ;	tData = {} ; tDate = {}
	tContext ={} ; tProject = {}
	fLines={}
	ntime = os.time()
	local hFile = io.open(SKIN:MakePathAbsolute(sFileName),'a+')
	
	if not hFile then
		print('File error'); return 'File error';
	else
	
		for line in hFile:lines() do
			table.insert(fLines,line)
		end --for line
			
	end -- if
	
	if sUserInput ~="" then
			hFile:write(os.date("%Y",os.time()),"-",os.date("%m",os.time()),"-",os.date("%d",os.time())," ",sUserInput,"\n")  -- add task via userinput
			SKIN:Bang('!Refresh')
			print("userinput")	
	end	--if	
	
		
	if sKeyword=="" then print ("keyword missing"); return 'file error' end
		
	for i,v in ipairs(fLines) do
			
		for taskage in string.gmatch(v,"%d+-%d+-%d+") do
			strdate = string.gmatch(taskage,"%d+")
			syear = strdate() ;	smonth = strdate() ; sday = strdate()
			ttime = os.time{year=syear, month=smonth, day=sday}
			tdiff = os.difftime(ntime,ttime)
			
			if calc(a) > 365 then
				cyear=math.floor(calc(a)/365)
				tage = " ["..cyear.." year]"
			elseif calc(a) > 30 then
				cmonth = math.floor(calc(a)/30)
				tage = " ["..cmonth.." month]"
			elseif calc(a) > 7 then
				cweek = math.floor(calc(a)/7)
				tage = " ["..cweek.." week]"
			elseif calc(a) <= 0 then
				tage = " [today]"
			else
				tage = " ["..calc(a).." day]"
			end -- if
			
		end --for
		
		if sKeyword == "Today" or sKeyword =="Later" then 
			for sdue in string.gmatch(v,"due:%d+/%d+/%d+") do
			strdate = string.gmatch(sdue,"%d+")
			sday = strdate() ;	smonth = strdate() ;		syear = strdate()
			ttime = os.time{year=syear, month=smonth, day=sday}
			tdiff = os.difftime(ntime,ttime)
			local sline3=string.sub(v,12) --> remove date position 1-11
				
				if calc(a) >= 0 and sKeyword == "Today" then
					table.insert(tData,sline3)
					table.insert(tNum,string.format('%02d',i))--> insert padzero line number 
					table.insert(tDate,tage)
				end -- if
				if calc(a) <0 and calc(a) >-7 and sKeyword == "Later" then
					table.insert(tData,sline3)
					table.insert(tNum,string.format('%02d',i))
					table.insert(tDate,tage)
				end -- if
		
			end--for sdue
		elseif sKeyword == "Priority" then
			for spriority in string.gmatch(v,"%d%s%(%a%)") do
			local sline4=string.sub(v,12) --> remove date position 1-11
				table.insert(tNum,string.format('%02d',i))
				table.insert(tData,sline4)
				table.insert(tDate,tage)
			end -- for spriority
		elseif sKeyword == "All" then
				local sline4=string.sub(v,12) --> remove date position 1-11
				table.insert(tNum,string.format('%02d',i))
				table.insert(tData,sline4)
				table.insert(tDate,tage)
		
		elseif string.find(v,sKeyword) then
			local sline2=string.sub(v,12) --> remove date position 1-11
			table.insert(tNum,string.format('%02d',i))--> insert padzero line number 
			table.insert(tData,sline2) 
			table.insert(tDate,tage)
		end --if
		
		for context in string.gmatch(v,"@[%w]+") do --> context label
			if not tContext[context] then
			table.insert(tContext,context)
			tContext[context] = true
			end --if
		end --for context
		
		for project in string.gmatch(v,"\+[%w]+") do --> project label
			if not tProject[project] then
			table.insert(tProject,project)
			tProject[project] = true
			end--if
		end--for project
		
	end --for
	fLines=nil
	
	io.close(hFile)
	
	   	NewNumber = #tData --> calc no of task containing context ToDotype
		SKIN:Bang('!SetOption ToDoTypeTitle Text \"'..sKeyword..' ยท '..NewNumber..'\"')
		print(NewNumber)
		
	for i = 1, (#tData < 8) and #tData or 7 do
		SKIN:Bang('!SetOption Num'..i..' Text \"'..tNum[i]..'\"')
		SKIN:Bang('!SetOption Task'..i..' Text \"'..tData[i]..'\"')
		SKIN:Bang('!SetOption Mark'..i..' Text \"'..tDate[i]..'\"')
		SKIN:Bang('!SetOption Task'..i..' LeftMouseDoubleClickAction """!CommandMeasure "DoneScript" done(\"'..tNum[i]..'\")"""')
		
	end
	
	for i = 1, (#tContext < 11) and #tContext or 10 do
    SKIN:Bang('!SetOption Context'..i..' Text \"'..tContext[i]..'\"')
	SKIN:Bang('!SetOption Context'..i..' LeftMouseUpAction """!Execute [!WriteKeyValue Variables Keyword \"'..tContext[i]..'\"][!Refresh]"""')
	end
	
	for i = 1, (#tProject < 9) and #tProject or 8 do
    SKIN:Bang('!SetOption Project'..i..' Text \"'..tProject[i]..'\"')
	SKIN:Bang('!SetOption Project'..i..' LeftMouseUpAction """!Execute [!WriteKeyValue Variables Keyword \"'..tProject[i]..'\"][!Refresh]"""')
	end
	SKIN:Bang('!WriteKeyValue Variables UserInput ""') -- return userinput to nil
	SKIN:Bang('!DisableMeasure MeasureScript')
	
end -->Update

function calc(a) -- calc day
	local calc = math.floor(tdiff/86400)
	return calc
end -- func calc

Code: Select all

--done.txt
function Initialize()

   sFileName 	= SELF:GetOption('FileName')
   sDonetxt 	= SELF:GetOption('Donetxt')
 end -- Initialize
 
function done(n)
	fLines={}
	t=0
	local hFile = io.open(sFileName,'r+')
	if not hFile then
		print('File error'); return 'File error';
	else
		for line in hFile:lines() do
			table.insert(fLines,line)
			t=t+1
		end --for line
	end--if		
	print(t)
	io.close(hFile)
	
	local aFile = io.open(sDonetxt,'a+')
	local hFile = io.open(sFileName,'w+')
	
	for line in hFile:lines() do
		table.insert(fLines,line)
	end --for line
		print(n)
		for i=1,t do
			if i ~= n then 
			hFile:write(fLines[i],"\n")
			else
			--aFile:write(fLines[i],"\n")
			aFile:write("x ",os.date("%Y",os.time()),"-",os.date("%m",os.time()),"-",os.date("%d",os.time())," ",fLines[i],"\n")
			end -- if
		end --for line
		
	io.close(hFile)
	io.close(aFile)
	SKIN:Bang('!Refresh')
	SKIN:Bang('!DisableMeasure DoneScript')
	--return done()
	
 end -- done
i had thought for days on how to archive task n remove task from the todo.txt to done.txt.

For now i create two script test.lua to display the parse task from todo.txt and done.lua to rewite todo.txt by removing completed task to done.txt.

skin.ini

Code: Select all

[MeasureScript]
Measure=Script
ScriptFile="#CURRENTPATH#test.lua"
FileName="D:\Dropbox\Rainmeter\1 - WHITE\todo.txt"
Disabled=0

[DoneScript]
Measure=Script
ScriptFile="#CURRENTPATH#done.lua"
FileName="D:\Dropbox\Rainmeter\1 - WHITE\todo.txt"
Donetxt="D:\Dropbox\Rainmeter\1 - WHITE\done.txt"
Disabled=0
For now i am happy with the skin. Maybe i will improve lua script progressively. Just wishing some feedbacks

Re: Lua Script todo.txt

Posted: April 12th, 2012, 7:49 am
by aidayong
hmm..thinking of adding badge no (ala ipad) to indicate remaining task according to priority, today etc.

Wishing if input can pop out on screen by assign shortcut key like launchy or executor.

Re: Lua Script todo.txt

Posted: April 15th, 2012, 11:57 pm
by aidayong
Hmm i out of idea how to execute $UserInput$ via lua script. I have try using double quote n backlash.

My thoughts is to execute inputtext with default value such as task1 so i could edit task n rewrite the textfile.

todo.lua

Code: Select all

SKIN:Bang('!SetOption EditTask1 Command1 """!Execute [\"$UserInput$\"] DefaultValue=task1"""')

Re: Lua Script todo.txt

Posted: January 28th, 2013, 10:27 pm
by shaggoth
can you share your final version?

Re: Lua Script todo.txt

Posted: May 24th, 2013, 3:35 am
by Tkael
+1 on the request to share your work. I love the idea of combining Todo.txt with Rainmeter.

Re: Lua Script todo.txt

Posted: July 4th, 2017, 9:28 pm
by rbriddickk84
Hi there! (Solved my problem :) )

I just started writing my ToDo skin in Rainmeter, only difference is that my calculations about the date and time would be from rainmeter-side. I only wanted to sort the dates and times in LUA.
Here is the INI code:

Code: Select all

[Rainmeter]
Update=500
AccurateText=1

[Variables]
fsize=12
frel=16
ident1=170529
ident2=170912
ident3=170630
idx1=0
idx2=0
idx3=0

[ScriptCaller]
Measure=Script
ScriptFile="#@#Scripts\sorter.lua"
UpdateDivider=-1
DynamicVariables=1

[SquareBack]
Meter=Image
SolidColor=0,0,0
X=0
Y=0
W=50
H=50
LeftMouseUpAction=[!UpdateMeasure ScriptCaller]

[DebugTxt1]
Meter=String
Group=ttt
X=4
Y=38
FontSize=#fsize#
FontColor=255,255,255
Text=#idx1#
Prefix="A ="
;UpdateDivider=-1
DynamicVariables=1
Antialias=1
Hidden=0

[DebugTxt2]
Meter=String
Group=ttt
X=0r
Y=#frel#r
FontSize=#fsize#
FontColor=255,255,255
Text=#idx2#
Prefix="B ="
;UpdateDivider=-1
DynamicVariables=1
Antialias=1
Hidden=0

[DebugTxt3]
Meter=String
Group=ttt
X=0r
Y=#frel#r
FontSize=#fsize#
FontColor=255,255,255
Text=#idx3#
Prefix="C ="
;UpdateDivider=-1
DynamicVariables=1
Antialias=1
Hidden=0
And the LUA code:

Code: Select all

function Initialize()
idA = SKIN:GetVariable('ident1', 'n/a')
idB = SKIN:GetVariable('ident2', 'n/a')
idC = SKIN:GetVariable('ident3', 'n/a')
list = {}
x = 0
_G.idt1=0
_G.idt2=0
_G.idt3=0
end 

--#.........................................................#--
function Update()
	ListAll = { 
	A = idA; 
	B = idB; 
	C = idC;
	}
	
	for k,v in pairs(ListAll, function(t,a,b) return t[a] < t[b] end) 
		do 
		x = x + 1
		list[x] = v
		
	end
	
	for k,v in pairs(list)do
		_G["idt"..k] = v
		
	end
--print(idt1,idt2,idt3)
SKIN:Bang('!SetVariable', 'idx1', idt1)
SKIN:Bang('!SetVariable', 'idx2', idt2)
SKIN:Bang('!SetVariable', 'idx3', idt3)

end -- function Update
Here the" ident1" variable in the ini file is some date in short format yymmdd without any spaces, only 6 numbers.
The LUA script reads those values, and sort them in chronologically correct order, and save those in other lua variables.
Then with a bang i pass back the corrected variables (which i swet blood to figure it out xD ).

Hope this helps for someone! :)