1 -- Authors: Sadrul Habib Chowdhury <imadil@gmail.com>
2 -- License: Public domain
3 -- Last Changed: Unknown
5 -- schedule.lua: schedule notification script
7 -- You can schedule some messages to show up in the statusbar at
11 -- y <year> <month> <date> <hour> <minute> <message>
13 -- m <month> <date> <hour> <minute> <message>
15 -- d <date> <hour> <minute> <message>
17 -- <hour> <minute> <message>
19 -- Current year/month/date will be used if you do not specify one. Messages
20 -- need not be within quotes. Some examples follow:
23 -- y 2005 4 1 2 0 "April fool!!" --> 1st April, 2005, 2 am
24 -- m 4 5 2 0 "Some message" --> 5th April of the current year, 2 am
25 -- d 5 2 0 "Other message" --> 5th of the current month and year, 2 am
26 -- 20 0 Last message --> 8 pm of today
29 -- The script now saves notification information in a file in the userdir
30 -- (usually ~/.ion3/schedule_save.lua). So the notifications stay after a
34 -- Sadrul Habib Chowdhury (Adil)
35 -- imadil at gmail dot com
37 if not mod_statusbar
then return end
40 -- how often should the script check for scheduled messages?
45 interval
= 60 * 1000, -- check every minute
46 save_filename
= "schedule_save.lua"
50 local timer
= nil -- the timer
51 local list
= nil -- doubly linked list of messages
54 -- extract the first token
56 function schedule
.get_token(str
)
58 bg
, fn
= string.find(str
, "%w+%s+")
59 return string.gsub(string.sub(str
, bg
, fn
), "%s+", ""),
64 -- show the notification when scheduled
66 function schedule
.notify()
68 local time
= os
.time()
69 if l
and time
> l
.time
then
70 io
.stderr
:write("schedule: " .. l
.message
.. "\n")
71 mod_statusbar
.inform("schedule", l
.message
)
72 mod_statusbar
.inform("schedule_hint", "important")
73 mod_statusbar
.update()
81 timer
:set(schedule
.interval
, schedule
.notify
)
87 function schedule
.insert_into_list(time
, message
)
91 if os
.time() > time
then return false end
104 if l
.time
> time
then
134 -- add messages in the queue
136 function schedule
.add_message(mplex
, str
)
138 local tm
= os
.date("*t")
140 token
, str
= schedule
.get_token(str
)
143 tm
.year
, str
= schedule
.get_token(str
)
144 tm
.month
, str
= schedule
.get_token(str
)
145 tm
.day
, str
= schedule
.get_token(str
)
146 tm
.hour
, str
= schedule
.get_token(str
)
147 elseif token
== "m" then
148 tm
.month
, str
= schedule
.get_token(str
)
149 tm
.day
, str
= schedule
.get_token(str
)
150 tm
.hour
, str
= schedule
.get_token(str
)
151 elseif token
== "d" then
152 tm
.day
, str
= schedule
.get_token(str
)
153 tm
.hour
, str
= schedule
.get_token(str
)
158 tm
.min, str
= schedule
.get_token(str
)
160 if schedule
.insert_into_list(os
.time(tm
), str
) then
161 mod_query
.message(mplex
, "Notification \"" .. str
.. "\" scheduled at " ..
162 os
.date("[%a %d %h %Y] %H:%M", os
.time(tm
)))
165 mod_query
.message(mplex
, "dude, can't schedule notification for past!")
169 function schedule
.ask_message(mplex
)
170 mod_query
.query(mplex
, TR("Schedule notification:"), nil, schedule
.add_message
,
175 -- show the scheduled notifications
177 function schedule
.show_all(mplex
)
179 local output
= "List of scheduled notifications:"
181 output
= output
.. "\n" .. os
.date("[%a %d %h %Y] %H:%M", l
.time
) ..
185 mod_query
.message(mplex
, output
)
191 function schedule
.save_file()
192 if not list
then return end
193 local t
= ioncore
.get_paths() -- saving the file in userdir
194 local f
= io
.open(t
.userdir
.."/".. schedule
.save_filename
, "w")
195 if not f
then return end
199 f
:write("schedule.insert_into_list("..l
.time
..", \""..l
.message
.."\")\n")
208 defbindings("WMPlex", {
209 -- you can change the key bindings to your liking
210 kpress(META
.."F5", "schedule.ask_message(_)"),
211 kpress(META
.."Shift+F5", function () -- clear notification
212 mod_statusbar
.inform("schedule", "")
213 mod_statusbar
.inform("schedule_hint", "")
214 mod_statusbar
.update()
216 kpress(META
.."Control+F5", "schedule.show_all(_)"),
219 dopath(schedule
.save_filename
, true) -- read any saved notifications
220 timer
= ioncore
.create_timer()
221 timer
:set(schedule
.interval
, schedule
.notify
)
222 mod_statusbar
.inform("schedule", "")