emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Make org-notify support macOS without DBus
@ 2021-10-20  9:27 Christopher M. Miles
  2021-10-20  9:58 ` [PATCH] " Christopher M. Miles
  0 siblings, 1 reply; 4+ messages in thread
From: Christopher M. Miles @ 2021-10-20  9:27 UTC (permalink / raw)
  To: emacs-orgmode list


[-- Attachment #1.1: Type: text/plain, Size: 460 bytes --]



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.


[-- Attachment #1.2: Type: text/html, Size: 475 bytes --]

[-- Attachment #2: Type: text/plain, Size: 37 bytes --]


<#secure method=pgpmime mode=sign>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-org-attach.el-add-a-new-command-to-archive-web-page.patch --]
[-- Type: text/x-patch, Size: 3119 bytes --]

From 6c667461b45e93059c6f801e485f7da4bfc3606c Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Fri, 29 May 2020 09:46:15 +0800
Subject: [PATCH] * org-attach.el: add a new command to archive web page

* lisp/org-attach.el (org-attach-url-archive): A new org-attach
dispatcher command to archive web page to a single file.

* lisp/org-agenda.el (org-attach-url-archive-command): A customize
option to specify external command for archiving web page.

* lisp/org-attach.el (org-attach-url-archive-page): A command
invoke external command to offline archive save web page.
---
 lisp/org-attach.el | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 57d1360fc..80855d147 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -204,6 +204,8 @@ (defcustom org-attach-commands
      "Attach a file using symbolic-link method.")
     ((?u ?\C-u) org-attach-url
      "Attach a file from URL (downloading it).")
+    ((?U) org-attach-url-archive
+     "Attach an offline version of web page URL.")
     ((?b) org-attach-buffer
      "Select a buffer and attach its contents to the task.")
     ((?n ?\C-n) org-attach-new
@@ -467,6 +469,31 @@ (defun org-attach-url (url)
   (let ((org-attach-method 'url))
     (org-attach-attach url)))
 
+(defun org-attach-url-archive (url)
+  (interactive "MURL of the web page be archived to attach: \n")
+  (let ((org-attach-method 'archive))
+    (org-attach-attach url)))
+
+(defcustom org-attach-url-archive-command
+  (file-name-nondirectory (executable-find "monolith"))
+  "The command used to offline archive web page.
+monolith can be found here: https://github.com/Y2Z/monolith."
+  :type 'string
+  :safe #'stringp
+  :group 'org-attach)
+
+(defun org-attach-url-archive-page (url target-file)
+  "Save an offline archive of web page."
+  (pcase org-attach-url-archive-command
+    ("monolith"
+     (make-process
+      :name "org-attach-offline"
+      :command (list org-attach-url-archive-command url "-o" target-file)
+      :sentinel (lambda (proc event) (message "org-attach-offline finished!"))
+      :buffer "*org-attach-url-archive*"))
+    (nil (warn "You must have a command availble for offline save web page!
+Set variable `org-attach-url-archive-command'."))))
+
 (defun org-attach-buffer (buffer-name)
   "Attach BUFFER-NAME's contents to current outline node.
 BUFFER-NAME is a string.  Signals a `file-already-exists' error
@@ -504,7 +531,8 @@ (defun org-attach-attach (file &optional visit-dir method)
        ((eq method 'cp) (copy-file file attach-file))
        ((eq method 'ln) (add-name-to-file file attach-file))
        ((eq method 'lns) (make-symbolic-link file attach-file))
-       ((eq method 'url) (url-copy-file file attach-file)))
+       ((eq method 'url) (url-copy-file file attach-file))
+       ((eq method 'archive) (org-attach-url-archive-page file attach-file)))
       (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (org-attach-tag)
       (cond ((eq org-attach-store-link-p 'attached)
-- 
2.26.2


[-- Attachment #4: Type: text/plain, Size: 248 bytes --]

-- 
[ 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



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

* [PATCH] Re: Make org-notify support macOS without DBus
  2021-10-20  9:27 Make org-notify support macOS without DBus Christopher M. Miles
@ 2021-10-20  9:58 ` Christopher M. Miles
  2021-10-20 15:54   ` Max Nikulin
  0 siblings, 1 reply; 4+ messages in thread
From: Christopher M. Miles @ 2021-10-20  9:58 UTC (permalink / raw)
  Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 706 bytes --]



Just update the email subject contains [PATCH]

"Christopher M. Miles" <numbchild@gmail.com> 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. 
>
>
> <#secure method=pgpmime mode=sign>
>
> [5. text/x-patch; 0001-org-attach.el-add-a-new-command-to-archive-web-page.patch]...



[-- Attachment #1.2: Type: text/html, Size: 949 bytes --]

[-- Attachment #2: Type: text/plain, Size: 37 bytes --]


<#secure method=pgpmime mode=sign>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-org-attach.el-add-a-new-command-to-archive-web-page.patch --]
[-- Type: text/x-patch, Size: 3119 bytes --]

From 6c667461b45e93059c6f801e485f7da4bfc3606c Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Fri, 29 May 2020 09:46:15 +0800
Subject: [PATCH] * org-attach.el: add a new command to archive web page

* lisp/org-attach.el (org-attach-url-archive): A new org-attach
dispatcher command to archive web page to a single file.

* lisp/org-agenda.el (org-attach-url-archive-command): A customize
option to specify external command for archiving web page.

* lisp/org-attach.el (org-attach-url-archive-page): A command
invoke external command to offline archive save web page.
---
 lisp/org-attach.el | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 57d1360fc..80855d147 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -204,6 +204,8 @@ (defcustom org-attach-commands
      "Attach a file using symbolic-link method.")
     ((?u ?\C-u) org-attach-url
      "Attach a file from URL (downloading it).")
+    ((?U) org-attach-url-archive
+     "Attach an offline version of web page URL.")
     ((?b) org-attach-buffer
      "Select a buffer and attach its contents to the task.")
     ((?n ?\C-n) org-attach-new
@@ -467,6 +469,31 @@ (defun org-attach-url (url)
   (let ((org-attach-method 'url))
     (org-attach-attach url)))
 
+(defun org-attach-url-archive (url)
+  (interactive "MURL of the web page be archived to attach: \n")
+  (let ((org-attach-method 'archive))
+    (org-attach-attach url)))
+
+(defcustom org-attach-url-archive-command
+  (file-name-nondirectory (executable-find "monolith"))
+  "The command used to offline archive web page.
+monolith can be found here: https://github.com/Y2Z/monolith."
+  :type 'string
+  :safe #'stringp
+  :group 'org-attach)
+
+(defun org-attach-url-archive-page (url target-file)
+  "Save an offline archive of web page."
+  (pcase org-attach-url-archive-command
+    ("monolith"
+     (make-process
+      :name "org-attach-offline"
+      :command (list org-attach-url-archive-command url "-o" target-file)
+      :sentinel (lambda (proc event) (message "org-attach-offline finished!"))
+      :buffer "*org-attach-url-archive*"))
+    (nil (warn "You must have a command availble for offline save web page!
+Set variable `org-attach-url-archive-command'."))))
+
 (defun org-attach-buffer (buffer-name)
   "Attach BUFFER-NAME's contents to current outline node.
 BUFFER-NAME is a string.  Signals a `file-already-exists' error
@@ -504,7 +531,8 @@ (defun org-attach-attach (file &optional visit-dir method)
        ((eq method 'cp) (copy-file file attach-file))
        ((eq method 'ln) (add-name-to-file file attach-file))
        ((eq method 'lns) (make-symbolic-link file attach-file))
-       ((eq method 'url) (url-copy-file file attach-file)))
+       ((eq method 'url) (url-copy-file file attach-file))
+       ((eq method 'archive) (org-attach-url-archive-page file attach-file)))
       (run-hook-with-args 'org-attach-after-change-hook attach-dir)
       (org-attach-tag)
       (cond ((eq org-attach-store-link-p 'attached)
-- 
2.26.2


[-- Attachment #4: Type: text/plain, Size: 247 bytes --]

-- 
[ 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


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

* Re: [PATCH] Re: Make org-notify support macOS without DBus
  2021-10-20  9:58 ` [PATCH] " Christopher M. Miles
@ 2021-10-20 15:54   ` Max Nikulin
  2021-10-21  4:07     ` [PATCH] {the CORRECT patch} Christopher M. Miles
  0 siblings, 1 reply; 4+ messages in thread
From: Max Nikulin @ 2021-10-20 15:54 UTC (permalink / raw)
  To: emacs-orgmode

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.



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

* Re: [PATCH] {the CORRECT patch}
  2021-10-20 15:54   ` Max Nikulin
@ 2021-10-21  4:07     ` Christopher M. Miles
  0 siblings, 0 replies; 4+ messages in thread
From: Christopher M. Miles @ 2021-10-21  4:07 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1546 bytes --]



Max Nikulin <manikulin@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.


[-- Attachment #1.2: Type: text/html, Size: 1976 bytes --]

[-- Attachment #2: Type: text/plain, Size: 37 bytes --]


<#secure method=pgpmime mode=sign>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-org-notify.el-Make-org-notify-action-notify-support-.patch --]
[-- Type: text/x-patch, Size: 3054 bytes --]

From 132a802d38c71569d6112ba933310af5318448b9 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@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)


[-- Attachment #4: Type: text/plain, Size: 247 bytes --]

-- 
[ 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


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

end of thread, other threads:[~2021-10-21  4:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-20  9:27 Make org-notify support macOS without DBus Christopher M. Miles
2021-10-20  9:58 ` [PATCH] " Christopher M. Miles
2021-10-20 15:54   ` Max Nikulin
2021-10-21  4:07     ` [PATCH] {the CORRECT patch} Christopher M. Miles

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).