i3status-anyevent: Add cron plugin
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# TODO: on i3wm reload (i3status restart), restore active windows status
|
||||
# TODO: on i3wm reload (i3status restart), restore active windows status
|
||||
# TODO: make battery plugin take into account charge level, add ability to call suspend2disk on critical charge level
|
||||
# TODO: More complex PA-plugin with volume adjustment of default sink
|
||||
|
||||
# we need to disable hash shuffling in order to make as less prints to stdout as possible
|
||||
BEGIN {
|
||||
@@ -18,6 +20,7 @@ use utf8;
|
||||
use open qw (:std :utf8);
|
||||
use Fcntl qw (:seek);
|
||||
use AnyEvent;
|
||||
use AnyEvent::Timer::Cron;
|
||||
use AnyEvent::I3;
|
||||
use JSON::XS;
|
||||
use Encode;
|
||||
@@ -150,7 +153,7 @@ sub add_events () {
|
||||
# Actually print messages there
|
||||
push @EP, AnyEvent->timer (
|
||||
after => 1, # sleep 1 second
|
||||
interval => 0.3, # then invoke every 1 second
|
||||
interval => 0.3, # then invoke every ~1/3 second
|
||||
cb => sub { # the callback to invoke
|
||||
my $OUTPUT;
|
||||
|
||||
@@ -664,6 +667,21 @@ sub add_events () {
|
||||
);
|
||||
}
|
||||
|
||||
# run all cron jobs from config
|
||||
if ($CONF->{'cron'}->{enabled}) {
|
||||
foreach my $task (@{$CONF->{'cron'}->{tasks}}) {
|
||||
push @EP, AnyEvent::Timer::Cron->new (
|
||||
time_zone => 'local',
|
||||
cron => $task->{time},
|
||||
cb => sub {
|
||||
foreach my $cmd (@{$task->{cmd}}) {
|
||||
`$cmd`;
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,32 @@
|
||||
]
|
||||
},
|
||||
|
||||
# Intended for use with desktop notifications
|
||||
# Because it inherits all env vars from i3, it can intercat with dbus and other
|
||||
# such user session services.
|
||||
"cron" : {
|
||||
"enabled" : 0,
|
||||
"tasks" : [
|
||||
{
|
||||
"time" : "55 23 * * *",
|
||||
"cmd" : [
|
||||
"notify-send 'Sleeping Time!' 'Take a nap.'",
|
||||
"mpg123 -q /usr/share/sounds/complete_quest_requirement.mp3"
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
# time in crontab format
|
||||
"time" : "55 12 * * 2,4",
|
||||
# commands as it should be invoked in bash script
|
||||
"cmd" : [
|
||||
"notify-send 'Pizza time!' 'M-m-m, tasty!'",
|
||||
"mpg123 -q /usr/share/sounds/complete_quest_requirement.mp3"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
# Weather to display Application Buttons
|
||||
"app_buttons": 1,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user