-
Notifications
You must be signed in to change notification settings - Fork 3
/
todo-pt.ahk
477 lines (441 loc) · 16.4 KB
/
todo-pt.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/*
Name : todo-pt - v0.5 - Universal TODO lists for Text Editors based on PlainTasks(1)
Source : https://github.com/hi5/todo-pt
AHKScript : http://ahkscript.org/boards/viewtopic.php?f=6&t=2366
Documentation : See readme.md at GH
License : MIT see COPYING.txt
Note : Some editors have plugins / addons which may proof more usable as they
can work with the particular features of that editor, for example:
(1) - Sublime Text (2 and 3) https://github.com/aziz/PlainTasks
(2) - EverEdit (2 and 3) https://github.com/everedit/addons/tree/master/mode/todo
*/
;todo-pt-label: ; uncomment if you wish to include todo-pt in your main script,
; also uncomment the Return below (after the Hotkey, IfWinActive line)
; Add a Gosub, todo-pt-label in the auto-execute section of your main script
#SingleInstance, force
#NoEnv
SetKeyDelay, -1
SetBatchLines, -1
SendMode, Input
SetTitleMatchMode, 2
; setup objTodo to store all settings
objTodo := {filenames: {1: ".todo", 2: ".todolist", 3: ".tasks", 4: ".taskpaper"} ; extensions to create context sensitive hotkeys
; The Unicode characters will only work properly if your TODO list is also in Unicode
; Some examples are given below - You can find more characters at http://unicode-table.com/en/
; If you want to use # ! ^ + wrapping these in {} is mandatory
, mark_open: "❑" ; Alternatives: - [ ] ☐ – — ›
, mark_done: "✔" ; Alternatives: * [x] ✔ ✓ ☑
, mark_pending: "✜" ; Alternatives: ☆ ★ ∆ ∇ ❖ ☉ ✜ ☀
, mark_cancelled: "✘" ; Alternatives: x [-] ✘ ⛝
, mark_project: "{#}" ; Alternatives: ➔ ➤ ■
, mark_indent: "`t" ; `t = TAB
, text_done: "@done"
, text_pending: "@pending"
, text_cancelled: "@cancelled"
, text_today: "@today"
, text_start: "@start"
, text_time: "@time"
, text_line: "--- ✄ ------------------------------"
, text_archive: "_____________________________________`nArchive"
; You can specify the date/time format as described here http://ahkscript.org/docs/commands/FormatTime.htm
; Note that Date and Time Formats are case sensitive
, date_format: " (dd/MM/yyyy - H:mm)"
; Set date_options_us to 1 if the above date_format is in American date/time format
; Only used for time calculation of time spent on task during @done when @start is present in task
, date_options_us: 0
; To correctly calculate (working) time spent on a task you can define the following
; settings - consult the time() function for a more detailed explanation:
; - Units (output units) can be d=days, h=hours, m=minutes, s=seconds
; - Params can be W,D,B,H,M,S
, date_options_units: "m" ; The time in minutes spent on a task is converted into hours:minutes format so it is advised not to alter this
, date_options_params: ""
, delay: 80 ; Delay in milliseconds after each clipboard action
, hotkey_task_done: "^d"
, hotkey_task_pending: "^+d"
, hotkey_task_cancel: "^m"
, hotkey_task_new: "^i"
, hotkey_task_start: "!s"
, hotkey_task_today: "!t"
, hotkey_archive: "^+s"
, hotkey_make_task: "^Enter"
, hotkey_help: "#F1"
, hotkey_new_project: "^p"
, hotkey_getline: "{home}{shift down}{end}{shift up}^x" ; for some editors ^x will suffice
, active_log : ""
, archive_log: "" }
for k, v in ObjTodo.Filenames
GroupAdd, ahkgroupTodo, %v%
Hotkey, % objTodo.hotkey_task_done , todo_hotkey_task_done
Hotkey, % objTodo.hotkey_task_pending, todo_hotkey_task_pending
Hotkey, % objTodo.hotkey_task_cancel , todo_hotkey_task_cancel
Hotkey, % objTodo.hotkey_task_new , todo_hotkey_task_new
Hotkey, % objTodo.hotkey_task_start , todo_hotkey_task_start
Hotkey, % objTodo.hotkey_task_today , todo_hotkey_task_today
Hotkey, % objTodo.hotkey_make_task , todo_hotkey_make_task
Hotkey, % objTodo.hotkey_new_project , todo_hotkey_new_project
Hotkey, % objTodo.hotkey_archive , todo_hotkey_archive
Hotkey, % objTodo.hotkey_help , todo_hotkey_help
Hotkey, IfWinActive
; Return ; Return from todo-pt-label - uncomment if you wish to include todo-pt in your main script
#IfWinActive ahk_group ahkgroupTodo
:*:-- ::
todo_ClipSave()
todo_SendClip(objTodo.text_line)
todo_ClipSave(1)
Return
#IfWinActive
#IfWinExist todohelper ahk_class AutoHotkeyGUI
Esc::
Gui, todo_pthelp:destroy
Return
#IfWinExist
todo_hotkey_archive:
todo_ClipSave()
objTodo.active_log:="", objTodo.archive_log:=""
clipboard:=""
Send ^a
Sleep 20
Send ^x ; select all + cut
Sleep % objTodo.delay
Loop, parse, Clipboard, `n, `r
{
If InStr(A_LoopField,todo_objGetValue("text_done",objTodo)) or InStr(A_LoopField,todo_objGetValue("text_cancelled",objTodo))
{
objTodo.archive_log .= Trim(A_LoopField) "`n"
continue
}
objTodo.active_log .= A_LoopField "`n"
}
If !InStr(clipboard,todo_objGetValue("text_archive",objTodo))
objTodo.active_log .= "`n`n" objTodo.text_archive "`n"
todo_SendClip(objTodo.active_log objTodo.archive_log)
Sleep % objTodo.delay
objTodo.active_log:="", objTodo.archive_log:=""
todo_ClipSave(1)
Return
todo_hotkey_new_project:
todo_ClipSave()
Send % "{end}"
todo_SendClip("`n" Trim(objTodo.mark_project,"{}") "Project:`n" objTodo.mark_indent objTodo.mark_open " ")
todo_ClipSave(1)
Return
todo_hotkey_make_task:
todo_ClipSave()
Send % "{home}"
todo_SendClip(objTodo.mark_indent objTodo.mark_open " ")
todo_ClipSave(1)
Return
todo_hotkey_task_new:
todo_ClipSave()
Send % "{end}{ctrl up}{shift up}{alt up}{enter}"
todo_SendClip(objTodo.mark_open " ")
todo_ClipSave()
Return
todo_hotkey_task_start:
todo_Command(objTodo.text_start)
Return
todo_hotkey_task_done:
todo_Command(objTodo.text_done)
Send % "{home}"
Return
todo_hotkey_task_pending:
todo_Command(objTodo.text_pending)
Send % "{home}"
Return
todo_hotkey_task_today:
Send % "{end}{space}"
todo_SendClip(objTodo.text_today)
Send % "{home}"
Return
todo_hotkey_task_cancel:
todo_Command(objTodo.text_cancelled)
Return
todo_hotkey_help:
todo_Help()
Return
todo_Command(CommandText) {
global objTodo
todo_GetLine()
If InStr(Clipboard, CommandText)
{
Clipboard:=RTrim(SubStr(Clipboard,1,InStr(Clipboard,CommandText))," @")
Sleep % objTodo.delay
todo_CheckMark(objTodo.mark_open)
todo_SendClip(Clipboard)
Send {end}
}
Else
{
if (CommandText = objTodo.text_done)
mark:=objTodo.mark_done
else if (CommandText = objTodo.text_pending)
mark:=objTodo.mark_pending
else if (CommandText = objTodo.text_cancelled)
mark:=objTodo.mark_cancelled
else if (CommandText = objTodo.text_start)
mark:=objTodo.mark_open
todo_CheckMark(mark)
Sleep % objTodo.delay
FormatTime, dtime, A_Now, % objTodo.date_format
if (InStr(Clipboard,todo_objGetValue("text_start",objTodo)) and (CommandText <> objTodo.text_cancelled))
{
RegExMatch(Clipboard, "iU)" todo_objGetValue("text_start",objTodo) " \K\((.*)\)", StartTime)
; calculate minutes from start to finish using todo_Time()
dtime:=todo_Time(SubStr(A_Now,1,12)
, todo_DateParse(Trim(StartTime,"()"),objTodo.date_options_us)
, objTodo.date_options_units
, objTodo.date_options_params)
; convert minutes to hours:minutes, wrapped in ()
dtime:="(" (SubStr("0" Round(dtime) // 60,-1)) ":" (SubStr("0" Mod(Round(dtime), 60),-1)) " hh:mm)"
FormatTime, dtimenow, A_Now, % objTodo.date_format
CommandText:=objTodo.text_done dtimenow " " objTodo.text_time " "
}
todo_SendClip(RTrim(clipboard) " " CommandText dtime)
}
todo_ClipSave(1)
}
todo_CheckMark(mark) {
global objTodo
Clipboard:=RegExReplace(Clipboard,"^(\s*)\Q" objTodo.mark_done "\E\s*","$1")
Clipboard:=RegExReplace(Clipboard,"^(\s*)\Q" objTodo.mark_open "\E\s*","$1")
Clipboard:=RegExReplace(Clipboard,"^(\s*)\Q" objTodo.mark_pending "\E\s*","$1")
Clipboard:=RegExReplace(Clipboard,"^(\s*)\Q" objTodo.mark_cancelled "\E\s*","$1")
Clipboard:=RegExReplace(Clipboard,"^(\s*)","$1" mark " ")
}
todo_GetLine() {
global objTodo
todo_ClipSave()
Send {home}{shift down}{end}{shift up}^x
Sleep % objTodo.delay
}
todo_SendClip(text) {
global objTodo
Clipboard:=text
SendInput, ^v
Sleep % objTodo.delay
}
todo_objGetValue(var,objTodo) {
for k, v in objTodo
if (k = var)
Return v
}
todo_ClipSave(action=0) {
static ClipSave
if (action = 0) ; save Clipboard
{
ClipSave:=ClipboardAll
}
else if (action = 1) ; restore Clipboard
{
Clipboard:=ClipSave
ClipSave:=""
}
else if (action = 2) ; clear ClipSave
ClipSave:=""
}
todo_Help() {
global objTodo
Gui, todo_pthelp:destroy
Gui, todo_pthelp:new, +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, todo_pthelp:Color, black,black
WinSet, Transparent, 150
Gui, todo_pthelp:Font,s20 cYellow bold,Calibri
Gui, todo_pthelp:add, text, x220 y10 , todo-pt // help
Gui, todo_pthelp:Font,s14 cWhite bold,Calibri
Gui, todo_pthelp:add, text, x20 yp+50, % objTodo.hotkey_new_project "`t= add a new Project + first task"
Gui, todo_pthelp:add, text, x20 yp+20, % objTodo.hotkey_task_new "`t= add a new task on the next line"
Gui, todo_pthelp:add, text, x20 yp+20, % objTodo.hotkey_make_task "`t= mark current line as a task"
Gui, todo_pthelp:add, text, x20 yp+40, % objTodo.hotkey_task_done "`t= mark task as done / back in TODO mode"
Gui, todo_pthelp:add, text, x20 yp+40, % objTodo.hotkey_task_pending "`t= mark task as pending / back in pending mode"
Gui, todo_pthelp:add, text, x20 yp+20, % objTodo.hotkey_task_cancel "`t= mark as cancelled / back in TODO mode"
Gui, todo_pthelp:add, text, x20 yp+20, % objTodo.hotkey_archive "`t= archive all completed tasks"
Gui, todo_pthelp:add, text, x20 yp+20, % objTodo.hotkey_task_start "`t= add / remove @start tag"
Gui, todo_pthelp:add, text, x20 yp+20, % objTodo.hotkey_task_today "`t= add / remove @today tag"
Gui, todo_pthelp:add, text, x20 yp+40, % objTodo.hotkey_help "`t= show help :-)"
Gui, todo_pthelp:add, text, x20 yp+20, Esc `t= close help window
Gui, todo_pthelp:show, w600 h340, todohelper
Return
}
; --- third party functions ---
todo_DateParse(str, americanOrder=0) {
/*
Function: DateParse
Converts almost any date format to a YYYYMMDDHH24MISS value.
Parameters:
str - a date/time stamp as a string
americanOrder - optional parameter to parse American day/months orders
Returns:
A valid YYYYMMDDHH24MISS value which can be used by FormatTime, EnvAdd and other time commands.
Authors:
polyethene https://github.com/polyethene/AutoHotkey-Scripts/
this is a modified version by formivore http://www.autohotkey.com/board/topic/18760-date-parser-convert-any-date-format-to-yyyymmddhh24miss/page-5#entry561591
*/
static monthNames := "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*"
, dayAndMonth := "(?:(\d{1,2}|" . monthNames . ")[\s\.\-\/,]+)?(\d{1,2}|" . monthNames . ")"
If RegExMatch(str, "i)^\s*(?:(\d{4})([\s\-:\/])(\d{1,2})\2(\d{1,2}))?"
. "(?:\s*[T\s](\d{1,2})([\s\-:\/])(\d{1,2})(?:\6(\d{1,2})\s*(?:(Z)|(\+|\-)?"
. "(\d{1,2})\6(\d{1,2})(?:\6(\d{1,2}))?)?)?)?\s*$", i) ;ISO 8601 timestamps
year := i1, month := i3, day := i4, t1 := i5, t2 := i7, t3 := i8
Else If !RegExMatch(str, "^\W*(\d{1,2}+)(\d{2})\W*$", t){
RegExMatch(str, "i)(\d{1,2})" ;hours
. "\s*:\s*(\d{1,2})" ;minutes
. "(?:\s*:\s*(\d{1,2}))?" ;seconds
. "(?:\s*([ap]m))?", t) ;am/pm
StringReplace, str, str, %t%
If Regexmatch(str, "i)(\d{4})[\s\.\-\/,]+" . dayAndMonth, d) ;2004/22/03
year := d1, month := d3, day := d2
Else If Regexmatch(str, "i)" . dayAndMonth . "[\s\.\-\/,]+(\d{2,4})", d) ;22/03/2004 or 22/03/04
year := d3, month := d2, day := d1
If (RegExMatch(day, monthNames) or americanOrder and !RegExMatch(month, monthNames)) ;try to infer day/month order
tmp := month, month := day, day := tmp
}
f = %A_FormatFloat%
SetFormat, Float, 02.0
d := (StrLen(year) == 2 ? "20" . year : (year ? year : A_YYYY))
. ((month := month + 0 ? month : InStr(monthNames, SubStr(month, 1, 3)) // 4 ) > 0 ? month + 0.0 : A_MM)
. ((day += 0.0) ? day : A_DD)
. t1 + (t1 == 12 ? t4 = "am" ? -12.0 : 0.0 : t4 = "pm" ? 12.0 : 0.0)
. t2 + 0.0 . t3 + 0.0
SetFormat, Float, %f%
return, d
}
todo_Time(to,from="",units="d",params=""){
/*
time() by HotKeyIt, source and examples:
http://www.autohotkey.com/board/topic/42668-time-count-days-hours-minutes-seconds-between-dates/
Parameters:
to and from can be in following format (from will be A_Now if empty):
- 20090101...
- 20090101000000
- Apr-04-2009 or Apr-04 for current year
- 01-01-2009 or 01-01 for current year
Units (output units) can be d=days, h=hours, m=minutes, s=seconds
params can be W,D,B,H,M,S
- W = WeeksDay to include, e.g. W2-6 (mon-fri) or W1.7 (exclude weekends)
- D = Day of Month to include, e.g. e D1-5 (to exclude D1.2.3)
- B = Bank holiday to exclude, e.g. B0101.3112
- H = Hours to include, e.g. H8-17 (to exclude use H0.1.2...)
- M = Minutes to include, e.g. M0-30 (to exclude use M0.1.2...)
- S = Seconds to include, e.g. S0-30 (to exclude use S0.1.2...)
*/
static _:="0000000000",s:=1,m:=60,h:=3600,d:=86400
,Jan:="01",Feb:="02",Mar:="03",Apr:="04",May:="05",Jun:="06",Jul:="07",Aug:="08",Sep:="09",Okt:=10,Nov:=11,Dec:=12
r:=0
units:=units ? %units% : 8640
If (InStr(to,"/") or InStr(to,"-") or InStr(to,".")){
Loop,Parse,to,/-.,%A_Space%
_%A_Index%:=RegExMatch(A_LoopField,"\d+") ? A_LoopField : %A_LoopField%
,_%A_Index%:=(StrLen(_%A_Index%)=1 ? "0" : "") . _%A_Index%
to:=SubStr(A_Now,1,8-StrLen(_1 . _2 . _3)) . _3 . (RegExMatch(SubStr(to,1,1),"\d") ? (_2 . _1) : (_1 . _2))
_1:="",_2:="",_3:=""
}
If (from and InStr(from,"/") or InStr(from,"-") or InStr(from,".")){
Loop,Parse,from,/-.,%A_Space%
_%A_Index%:=RegExMatch(A_LoopField,"\d+") ? A_LoopField : %A_LoopField%
,_%A_Index%:=(StrLen(_%A_Index%)=1 ? "0" : "") . _%A_Index%
from:=SubStr(A_Now,1,8-StrLen(_1 . _2 . _3)) . _3 . (RegExMatch(SubStr(from,1,1),"\d") ? (_2 . _1) : (_1 . _2))
}
count:=StrLen(to)<9 ? "days" : StrLen(to)<11 ? "hours" : StrLen(to)<13 ? "minutes" : "seconds"
to.=SubStr(_,1,14-StrLen(to)),(from ? from.=SubStr(_,1,14-StrLen(from)))
Loop,Parse,params,%A_Space%
If (unit:=SubStr(A_LoopField,1,1))
%unit%1:=InStr(A_LoopField,"-") ? SubStr(A_LoopField,2,InStr(A_LoopField,"-")-2) : ""
,%unit%2:=SubStr(A_LoopField,InStr(A_LoopField,"-") ? (InStr(A_LoopField,"-")+1) : 2)
count:=!params ? count : "seconds"
add:=!params ? 1 : (S2="" ? (M2="" ? (H2="" ? ((D2="" and B2="" and W="") ? d : h) : m) : s) : s)
While % (from<to){
FormatTime,year,%from%,YYYY
FormatTime,month,%from%,MM
FormatTime,day,%from%,dd
FormatTime,hour,%from%,H
FormatTime,minute,%from%,m
FormatTime,second,%from%,s
FormatTime,WDay,%from%,WDay
EnvAdd,from,%add%,%count%
If (W1 or W2){
If (W1=""){
If (W2=WDay or InStr(W2,"." . WDay) or InStr(W2,WDay . ".")){
Continue=1
}
} else If WDay not Between %W1% and %W2%
Continue=1
;else if (Wday=W2)
; Continue=1
If (Continue){
tempvar:=SubStr(from,1,8)
EnvAdd,tempvar,1,days
EnvSub,tempvar,%from%,seconds
EnvAdd,from,%tempvar% ,seconds
Continue=
continue
}
}
If (D1 or D2 or B2){
If (D1=""){
If (D2=day or B2=(day . month) or InStr(B2,"." . day . month) or InStr(B2,day . month . ".") or InStr(D2,"." . day) or InStr(D2,day . ".")){
Continue=1
}
} else If day not Between %D1% and %D2%
Continue=1
;else if (day=D2)
; Continue=1
If (Continue){
tempvar:=SubStr(from,1,8)
EnvAdd,tempvar,1,days
EnvSub,tempvar,%from%,seconds
EnvAdd,from,%tempvar% ,seconds
Continue=
continue
}
}
If (H1 or H2){
If (H1=""){
If (H2=hour or InStr(H2,hour . ".") or InStr(H2,"." hour)){
Continue=1
}
} else If hour not Between %H1% and %H2%
continue=1
;else if (hour=H2)
; continue=1
If (continue){
tempvar:=SubStr(from,1,10)
EnvAdd,tempvar,1,hours
EnvSub,tempvar,%from%,seconds
EnvAdd,from,%tempvar% ,seconds
continue=
continue
}
}
If (M1 or M2){
If (M1=""){
If (M2=minute or InStr(M2,minute . ".") or InStr(M2,"." minute)){
Continue=1
}
} else If minute not Between %M1% and %M2%
continue=1
;else if (minute=M2)
; continue=1
If (continue){
tempvar:=SubStr(from,1,12)
EnvAdd,tempvar,1,minutes
EnvSub,tempvar,%from%,seconds
EnvAdd,from,%tempvar% ,seconds
continue=
continue
}
}
If (S1 or S2){
If (S1=""){
If (S2=second or InStr(S2,second . ".") or InStr(S2,"." second)){
Continue
}
} else if (second!=S2)
If second not Between %S1% and %S2%
continue
}
r+=add
}
tempvar:=SubStr(count,1,1)
tempvar:=%tempvar%
Return (r*tempvar)/units
}