From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tassilo Horn Subject: Re: notify, when something to do Date: Sun, 23 Oct 2011 18:20:07 +0200 Message-ID: <87pqhnade0.fsf@thinkpad.tsdh.de> References: <87vcrgqav9.fsf@micropit.couberia.bzh> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:49019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RI0me-00009y-TA for emacs-orgmode@gnu.org; Sun, 23 Oct 2011 12:20:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RI0md-0004Ov-FS for emacs-orgmode@gnu.org; Sun, 23 Oct 2011 12:20:24 -0400 Received: from lo.gmane.org ([80.91.229.12]:47140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RI0mc-0004Oq-V2 for emacs-orgmode@gnu.org; Sun, 23 Oct 2011 12:20:23 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RI0mb-0002LR-7b for emacs-orgmode@gnu.org; Sun, 23 Oct 2011 18:20:21 +0200 Received: from 91-67-169-145-dynip.superkabel.de ([91.67.169.145]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Oct 2011 18:20:21 +0200 Received: from tassilo by 91-67-169-145-dynip.superkabel.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Oct 2011 18:20:21 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org pmlists@free.fr (Peter Münster) writes: Hi Peter, > I would like to be notified[1], when a todo item enters the warning > period, scheduled time, or deadline. I export my org entries as appt alarms, so that I get system notifications 15 minutes before meetings (every 1 minute until I discard them). Here's the code: --8<---------------cut here---------------start------------->8--- (defvar th-notify-title-to-id-map (make-hash-table :test 'string=) "Maps TITLE values of notifications to the last notification ID. If ID is -1, then any further notifications with that body will be skipped.") (defun th-notify (&rest args) "Create a notification popup. For ARGS, see `notifications-notify'. There's some new default behavior over the function above: - Notifications with same :body replace each other. :body, because my notifications are usually something like :title \"Meeting with Hugo\" :body \"In 15 Minutes\" where each minute a similar notification with decreasing minutes in the :body is triggered. - If a notification was dismissed, then don't show any notifications with that :title anymore (the next 15 minutes). - Use unlimited timeout." (require 'notifications) (let* ((title (plist-get args :body)) (body (plist-get args :body)) (replaces-id (or (plist-get args :replaces-id) (gethash title th-notify-title-to-id-map))) (on-close (or (plist-get args :on-close) `(lambda (id reason) (when (eq reason 'dismissed) ;; Mark as "don't show again!" (puthash ,title -1 th-notify-title-to-id-map) ;; But clear that "dont-show-mark" after 15 minutes (run-with-timer (* 15 60) nil (lambda () (remhash ,title th-notify-title-to-id-map))))))) ;; 0 means, it should not expire at all (timeout (or (plist-get args :timeout) 0))) (unless (eql replaces-id -1) (puthash title (apply 'notifications-notify (th-plist-put-many args :timeout timeout :replaces-id replaces-id :on-close on-close)) th-notify-title-to-id-map)))) (defun th-appt-alarm (mins time text) "Show a notification popup (or update the current one) for the appt with TEXT in MINS minutes (a string)." (let ((body (substring-no-properties text))) (th-notify :title text :body (concat "Appointment " (if (string= mins "0") "NOW:" (concat "in " mins " minutes:")))))) (setq appt-display-format 'window appt-disp-window-function 'th-appt-alarm appt-display-interval 1 appt-display-duration 60) (defun th-org-agenda-to-appt () (require 'org-agenda) (org-agenda-to-appt t) (appt-activate 1)) (th-org-agenda-to-appt) (add-hook 'org-finalize-agenda-hook 'th-org-agenda-to-appt) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo