Max Nikulin <maniku...@gmail.com> writes:

> On 20/10/2021 16:58, Christopher M. Miles wrote:
>> Just update the email subject contains [PATCH]
>> "Christopher M. Miles"  writes:
>>     Mostly Emacs versions under macOS does not have compiled with DBus.
>>     Or still don't work even compiled with DBus even macOS installed
>>     dbus with homebrew. I'm under this situation and problem. Spend lot
>>     of time have not solution to solve this problem. So I give up on
>>     Emacs DBus support under macOS to make "notifications.el" work.
>>     I added patch on org-notify.el to make it invoke AppleScript command
>>     to display notifications. Hope it help some macOS users.
>>     [5. text/x-patch;
>>     0001-org-attach.el-add-a-new-command-to-archive-web-page.patch]… 
>
> Christopher, the patch you attached is related to org-attach and e.g. 
> handling of monolith links.
> Does it really solve some notification problem?
>
> Bastien committed your earlier patch for notification through applescript 
> (that does not protect
> backslashes in notification text):
>
> b80b0a517de7be94c70d3d6537899a94ac046fab
> org-clock.el: Make org-notify support macOS notification
>
> I would expect that dbus-related options has lower priority than applescript.

Sorry, I misplaced the patch attachment file. I will attach the correct one. 
Sorry about this.
Because org-contrib has separated from org-mode. So I go into wrong directory.

This is a patch for org-contrib/lisp/org-notify.el. Thanks for reviewing.

<#secure method=pgpmime mode=sign>

>From 132a802d38c71569d6112ba933310af5318448b9 Mon Sep 17 00:00:00 2001
From: stardiviner <numbch...@gmail.com>
Date: Wed, 20 Oct 2021 17:19:14 +0800
Subject: [PATCH] org-notify.el: Make org-notify-action-notify support macOS
 without DBus

* lisp/org-notify.el (org-notify-action-notify): Use Emacs to invoke
AppleScript code to send notification when DBus not available under macOS.
---
 lisp/org-notify.el | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/lisp/org-notify.el b/lisp/org-notify.el
index 7f9a814..e8f8cf6 100644
--- a/lisp/org-notify.el
+++ b/lisp/org-notify.el
@@ -379,16 +379,27 @@ org-notify window.  Mostly copied from `appt-select-lowest-window'."
 (defun org-notify-action-notify (plist)
   "Pop up a notification window."
   (require 'notifications)
-  (let* ((duration (plist-get plist :duration))
-         (id (notifications-notify
-              :title     (plist-get plist :heading)
-              :body      (org-notify-body-text plist)
-              :timeout   (if duration (* duration 1000))
-              :urgency   (plist-get plist :urgency)
-              :actions   org-notify-actions
-              :on-action 'org-notify-on-action-notify)))
-    (setq org-notify-on-action-map
-          (plist-put org-notify-on-action-map id plist))))
+  (cond ((and (featurep 'dbus) (boundp 'dbusbind))
+         (let* ((duration (plist-get plist :duration))
+                (id (notifications-notify
+                     :title     (plist-get plist :heading)
+                     :body      (org-notify-body-text plist)
+                     :timeout   (if duration (* duration 1000))
+                     :urgency   (plist-get plist :urgency)
+                     :actions   org-notify-actions
+                     :on-action 'org-notify-on-action-notify)))
+           (setq org-notify-on-action-map
+                 (plist-put org-notify-on-action-map id plist))))
+        ((fboundp 'ns-do-applescript)
+         (ns-do-applescript
+          (format "display notification \"%s\" with title \"%s\" sound name \"Frog\""
+                  (replace-regexp-in-string "\"" "#" (org-notify-body-text plist))
+                  (replace-regexp-in-string "\"" "#" (plist-get plist :heading))))
+         (when org-notify-audible
+           ;; TODO make audio speaking async. By default `ns-do-applescript' will block Emacs.
+           (ns-do-applescript
+            (format "say \"%s\""
+                    (replace-regexp-in-string "\"" "#" (plist-get plist :heading))))))))
 
 (defun org-notify-action-notify/window (plist)
   "For a graphics display, pop up a notification window, for a text
@@ -398,8 +409,7 @@ terminal an emacs window."
     (org-notify-action-window plist)))
 
 ;;; Provide a minimal default setup.
-(org-notify-add 'default '(:time "1h" :actions -notify/window
-				 :period "2m" :duration 60))
+(org-notify-add 'default '(:time "1h" :actions -notify/window :period "2m" :duration 60))
 
 (provide 'org-notify)
 
-- 
2.30.1 (Apple Git-130)

-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

Reply via email to