unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* use linux native notifications with tea-time
@ 2011-06-06 19:28 Benjamin Slade
  2011-06-08  6:51 ` Tassilo Horn
  2011-06-08 14:42 ` Dove Young
  0 siblings, 2 replies; 6+ messages in thread
From: Benjamin Slade @ 2011-06-06 19:28 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'm trying to set up tea-time.el to use native linux notification
(through notify-send).

The current "notification function" in tea-time.el is:

------------
(defun show-notification (notification)
  "Show notification. Use mumbles."
 (if (program-exists "mumbles-send")
    (start-process "tea-time-mumble-notification" nil "mumbles-send"
notification)
  (message notification)
 ))
---------------



What would be the most straightforward way of using _notify-send_ in
this function?

(I tried:

---
(defun show-notification (notification)
  (shell-command (concat "notify-send " notification)
))
---

but I get an "Invalid number of options" error.)

thanks,
  --Ben
-----------------------------------------------------------------------------------------------------
Benjamin Slade
Dept. of Linguistics
University of Illinois at Urbana-Champaign
[ http://www.jnanam.net/slade/ ]

Stæfcræft & Vyākaraṇa (lingblog) - http://staefcraeft.blogspot.com
The Babbage Files (techblog) - http://babbagefiles.blogspot.com

-----------------------------------------------------------------------------------------------------
  परो ऽक्ष॑कामा हि देवाः
    'The gods love the obscure.' (Śatapathabrāmaṇa 6.1.1.2)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: use linux native notifications with tea-time
  2011-06-06 19:28 use linux native notifications with tea-time Benjamin Slade
@ 2011-06-08  6:51 ` Tassilo Horn
  2011-06-08 14:42 ` Dove Young
  1 sibling, 0 replies; 6+ messages in thread
From: Tassilo Horn @ 2011-06-08  6:51 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Benjamin,

in case you are using Emacs 24, that comes with notifications.el, which
allows sending off notifications via DBUS.  Just check the function
`notifications-notify'.

For my personal use, I've created some wrapper around it that changes
some defaults and allows for dismissing notifications.

--8<---------------cut here---------------start------------->8---
(defun th-plist-put-many (plist &rest args)
  "Put all prop-value pairs given in ARGS into PLIST.

Example:
  (th-plist-put-many '(:a 1 :b 2) :a 10 :c 30 :d 40)
  ==> (:a 10 :b 2 :c 30 :d 40)"
  (let ((rest args))
    (while rest
      (setq plist (plist-put plist (car rest) (cadr rest)))
      (setq rest (cddr rest)))
    plist))

(defvar th-notify-body-to-id-map (make-hash-table :test 'string=)
  "Maps BODY 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 \"In 15 Minutes\"
      :body \"Meeting with Hugo\"

    where each minute a similar notification with decreasing
    minutes in the :title is triggered.

  - If a notification was dismissed, then don't show any
    notifications with that :body anymore (the next 15 minutes).

  - Use unlimited timeout."
  (require 'notifications)
  (let* ((body (plist-get args :body))
	 (replaces-id (or (plist-get args :replaces-id)
			  (gethash body th-notify-body-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 ,body -1 th-notify-body-to-id-map)
			    ;; But clear that "dont-show-mark" after 15 minutes
			    (run-with-timer (* 15 60) nil
					    (lambda ()
					      (remhash ,body th-notify-body-to-id-map)))))))
	 (timeout (or (plist-get args :timeout)
		      ;; 0 means, it should not expire at all
		      0)))
    (unless (eql replaces-id -1)
      (puthash body (apply 'notifications-notify
			   (th-plist-put-many args
					      :timeout timeout
					      :replaces-id replaces-id
					      :on-close on-close))
	       th-notify-body-to-id-map))))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: use linux native notifications with tea-time
  2011-06-06 19:28 use linux native notifications with tea-time Benjamin Slade
  2011-06-08  6:51 ` Tassilo Horn
@ 2011-06-08 14:42 ` Dove Young
  2011-06-08 15:37   ` Benjamin Slade
  2011-06-10  5:23   ` Kevin Rodgers
  1 sibling, 2 replies; 6+ messages in thread
From: Dove Young @ 2011-06-08 14:42 UTC (permalink / raw)
  To: Benjamin Slade, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1843 bytes --]

In your function, the actual command send to shell is 'notify-send Time is
up! 1 minutes'

dove@bash-4.2$ notify-send Time is up! 1 minutes
Invalid number of options.

You should modify your function in this way, quote notification string
before send it to your shell

(defun show-notification (notification)
 (shell-command (format "notify-send '%s'" notification) )
)


2011/6/7 Benjamin Slade <slade@jnanam.net>

> Hi,
>
> I'm trying to set up tea-time.el to use native linux notification
> (through notify-send).
>
> The current "notification function" in tea-time.el is:
>
> ------------
> (defun show-notification (notification)
>  "Show notification. Use mumbles."
>  (if (program-exists "mumbles-send")
>    (start-process "tea-time-mumble-notification" nil "mumbles-send"
> notification)
>  (message notification)
>  ))
> ---------------
>
>
>
> What would be the most straightforward way of using _notify-send_ in
> this function?
>
> (I tried:
>
> ---
> (defun show-notification (notification)
>  (shell-command (concat "notify-send " notification)
> ))
> ---
>
> but I get an "Invalid number of options" error.)
>
> thanks,
>  --Ben
>
> -----------------------------------------------------------------------------------------------------
> Benjamin Slade
> Dept. of Linguistics
> University of Illinois at Urbana-Champaign
> [ http://www.jnanam.net/slade/ ]
>
> Stæfcræft & Vyākaraṇa (lingblog) - http://staefcraeft.blogspot.com
> The Babbage Files (techblog) - http://babbagefiles.blogspot.com
>
>
> -----------------------------------------------------------------------------------------------------
>   परो ऽक्ष॑कामा हि देवाः
>     'The gods love the obscure.' (Śatapathabrāmaṇa 6.1.1.2)
>
>


-- 
M-x Thinks

[-- Attachment #2: Type: text/html, Size: 2545 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: use linux native notifications with tea-time
  2011-06-08 14:42 ` Dove Young
@ 2011-06-08 15:37   ` Benjamin Slade
  2011-06-10  5:33     ` Kevin Rodgers
  2011-06-10  5:23   ` Kevin Rodgers
  1 sibling, 1 reply; 6+ messages in thread
From: Benjamin Slade @ 2011-06-08 15:37 UTC (permalink / raw)
  To: Dove Young, help-gnu-emacs

Thanks Dove & Tassilo,

I actually got it to work by redefining the "show-notification"
function as follows:

(defun show-notification (notification)
"Show notification. Use notify-send."
(start-process "tea-time-notify-notification" nil "notify-send" "-i"
(expand-file-name "~/path/to/your/icon/YourIconName.png") "Emacs Tea
Timer" notification)
)

Tassilo - no, I'm still using 23.2.1, but I'll keep your suggestions
in mind for the future.

cheers,
  --Ben

On 8 June 2011 09:42, Dove Young <dove.young@gmail.com> wrote:
> In your function, the actual command send to shell is 'notify-send Time is
> up! 1 minutes'
>
> dove@bash-4.2$ notify-send Time is up! 1 minutes
> Invalid number of options.
>
> You should modify your function in this way, quote notification string
> before send it to your shell
>
> (defun show-notification (notification)
>  (shell-command (format "notify-send '%s'" notification) )
> )
>
>
> 2011/6/7 Benjamin Slade <slade@jnanam.net>
>>
>> Hi,
>>
>> I'm trying to set up tea-time.el to use native linux notification
>> (through notify-send).
>>
>> The current "notification function" in tea-time.el is:
>>
>> ------------
>> (defun show-notification (notification)
>>  "Show notification. Use mumbles."
>>  (if (program-exists "mumbles-send")
>>    (start-process "tea-time-mumble-notification" nil "mumbles-send"
>> notification)
>>  (message notification)
>>  ))
>> ---------------
>>
>>
>>
>> What would be the most straightforward way of using _notify-send_ in
>> this function?
>>
>> (I tried:
>>
>> ---
>> (defun show-notification (notification)
>>  (shell-command (concat "notify-send " notification)
>> ))
>> ---
>>
>> but I get an "Invalid number of options" error.)
>>
>> thanks,
>>  --Ben
>>
>> -----------------------------------------------------------------------------------------------------
>> Benjamin Slade
>> Dept. of Linguistics
>> University of Illinois at Urbana-Champaign
>> [ http://www.jnanam.net/slade/ ]
>>
>> Stæfcræft & Vyākaraṇa (lingblog) - http://staefcraeft.blogspot.com
>> The Babbage Files (techblog) - http://babbagefiles.blogspot.com
>>
>>
>> -----------------------------------------------------------------------------------------------------
>>   परो ऽक्ष॑कामा हि देवाः
>>     'The gods love the obscure.' (Śatapathabrāmaṇa 6.1.1.2)
>>
>
>
>
> --
> M-x Thinks
>
>



-- 
-----------------------------------------------------------------------------------------------------
Benjamin Slade
Dept. of Linguistics
University of Illinois at Urbana-Champaign
[ http://www.jnanam.net/slade/ ]

Stæfcræft & Vyākaraṇa (lingblog) - http://staefcraeft.blogspot.com
The Babbage Files (techblog) - http://babbagefiles.blogspot.com

-----------------------------------------------------------------------------------------------------
  परो ऽक्ष॑कामा हि देवाः
    'The gods love the obscure.' (Śatapathabrāmaṇa 6.1.1.2)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: use linux native notifications with tea-time
  2011-06-08 14:42 ` Dove Young
  2011-06-08 15:37   ` Benjamin Slade
@ 2011-06-10  5:23   ` Kevin Rodgers
  1 sibling, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2011-06-10  5:23 UTC (permalink / raw)
  To: help-gnu-emacs

On 6/8/11 8:42 AM, Dove Young wrote:
> In your function, the actual command send to shell is 'notify-send Time is up! 1
> minutes'
>
> dove@bash-4.2$ notify-send Time is up! 1 minutes
> Invalid number of options.
>
> You should modify your function in this way, quote notification string before
> send it to your shell
>
> (defun show-notification (notification)
>   (shell-command (format "notify-send '%s'" notification) )
> )

Or let shell-quote-argument do the quoting for you:

(shell-command (format "notify-send %s" (shell-quote-argument notification)))

-- 
Kevin Rodgers
Denver, Colorado, USA




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: use linux native notifications with tea-time
  2011-06-08 15:37   ` Benjamin Slade
@ 2011-06-10  5:33     ` Kevin Rodgers
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2011-06-10  5:33 UTC (permalink / raw)
  To: help-gnu-emacs

On 6/8/11 9:37 AM, Benjamin Slade wrote:
> (defun show-notification (notification)
> "Show notification. Use notify-send."
> (start-process "tea-time-notify-notification" nil "notify-send" "-i"
> (expand-file-name "~/path/to/your/icon/YourIconName.png") "Emacs Tea
> Timer" notification)
> )

Since you don't need any shell features like indirection, calling the program
directly (instead of via the shell) is simpler: no quoting, and more efficient.

Whether call-process or start-process should be used in this case depends
on whether the program returns immediately or not, since the output from the
process isn't being used within Emacs.

-- 
Kevin Rodgers
Denver, Colorado, USA




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-10  5:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 19:28 use linux native notifications with tea-time Benjamin Slade
2011-06-08  6:51 ` Tassilo Horn
2011-06-08 14:42 ` Dove Young
2011-06-08 15:37   ` Benjamin Slade
2011-06-10  5:33     ` Kevin Rodgers
2011-06-10  5:23   ` Kevin Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).