:- use_module(library(lib)). :- lib(by_unix). :- lib(options). :- lib(debug_call). alert_defaults( Defs ) :- Defs = [ debug(false), title(title), type(both) ]. :- debuc(alert(info)). /** alert( +Opts ). Display an alert at a specific time. Opts * debug(Dbg=false) debugging * help print help * message(Mess) message * title(Title=title) title * type(Type=both) type of message: notify, zenity or both * when(At) when (currently at('HH:MM') and in(Min) are recognised) == % upsh alert help % supsh alert title=titlE message=messagE when=in=0.5 (Min) % supsh alert title=titlE message=messagE when=at=16\\:00 type=notify == @author nicos angelopoulos @version 0:1 2021/04/09 @tbd type check type */ alert( Args ) :- Self = alert, options_append( Self, Args, Opts ), alert_opts( Self, Opts ). alert_opts( _Self, Opts ) :- memberchk( help, Opts ), !, debuc( alert(info), 'supsh alert title=titlE message=messagE when=in=0.5', [] ), debuc( alert(info), 'supsh alert title=titlE message=messagE when=at=16\\\\:00 type=notify', [] ). alert_opts( Self, Opts ) :- options( when(When), Opts ), options( title(Tit), Opts ), options( message(Msg), Opts ), options( type(Type), Opts ), abs_time( When, Delay ), atert( Delay, Self, Tit, Msg, Type ). abs_time( in(Min), Delay ) :- !, Delay is Min * 60. abs_time( at(At), Delay ) :- get_time( NowStamp ), stamp_date_time( NowStamp, Now, local ), Now =.. [T0,TY,TM,TD,_TH,_TN,_TS,T7,T8,T9], atomic_list_concat( [Ha,Ma], ':', At ), atom_number( Ha, HH ), atom_number( Ma, MN ), AtD =.. [T0,TY,TM,TD,HH,MN,0,T7,T8,T9], date_time_stamp( AtD, AtStamp ), Delay is AtStamp - NowStamp, check_delay( Delay ). atert( Delay, Self, Tit, Msg, Type ) :- debuc( Self, 'Sleeping for : ~w', [Delay] ), sleep( Delay ), debuc( Self, 'Title: ~w', [Tit] ), debuc( Self, 'Msg: ~w', [Tit] ), get_time( NowStamp ), stamp_date_time( NowStamp, Now, local ), Now =.. [_T0,_TY,_TM,_TD,TH,TN,_TS,_T7,_T8,_T9], atomic_list_concat( [TH,':',TN,'\n',Msg], '', Full ), aterty( Type, Tit, Full ). aterty( both, Tit, Msg ) :- !, aterty( notify, Tit, Msg ), aterty( zenity, Tit, Msg ). aterty( notify, Tit, Msg ) :- !, @ 'notify-send'(Tit,Msg). aterty( zenity, Tit, Msg ) :- !, @ zenity(--info,--title,Tit,--text,Msg). check_delay( Delay ) :- Delay < 0, !, throw( negative_delay(Delay) ). check_delay( _ ).