Subject: bug#76120: This feature is not about "sharing", or a "native" anything.

From: Alvaro Ramirez <[email-masked]>
Date: Sat, 19 Jul 2025 17:34:34 +0100

Thank you Eli and Gerd.

Attaching 0008-Add-Send-to-context-menu-item-to-mouse-el.patch 
addressing your feedback:

1. Replaces call-process for shell-command-do-open
2. Enables using send-to on macOS via "emacs -nw"

Eli Zaretskii <[email-masked]> writes:

> Thanks!
>
> Alvaro, there's a bug in send-to.el.  Here:
>
>     (dolist (item items)
>       (with-temp-buffer
>         (unless (zerop (call-process
>                         shell-command-guess-open nil 
>                         (current-buffer) t
>                         (send-to--convert-item-to-filename
>                          item)))
>           (error "%s" (string-trim (buffer-string))))))))
>
> This passes the result of shell-command-guess-open to 
> call-process,
> but shell-command-guess-open returns a _shell_command_, not a 
> program
> name.  So the code should call call-process-shell-command or 
> maybe
> process-file-shell-command.
>
> For example, on MS-Windows shell-command-guess-open returns the
> command "start", but it is not necessarily the name of a 
> program, it
> is usually a built-in command of the Windows shell.

Found the shell-command-do-open function, a nice new addition, 
handling all supported OSs/cases.

Gerd Möllmann <[email-masked]> writes:

> Found a crash: Using send-to with in emacs -nw leads to a crash.
> Maybe send-to--ns-supported-p should check display-graphics-p?

Thanks. Hadn't thought of this. Should be fixed in 0008.

> And maybe a nice-to have: Building --withput-ns, which I 
> normally do,
> send-to "only" offers opening the file externally, which uses 
> the "open" command.
> Maybe it would be nice to support "open -a <app>"?

Could you share more details? If I'm understanding correctly, you 
mean asking users for a custom command?

If so, it's worth mentioning send-to-handlers, which enables 
adding custom handlers using preferred priority.

(defvar-local send-to-handlers '(((:supported 
. send-to--ns-supported-p)
                                  (:collect 
                                  . send-to--collect-items)
                                  (:send 
                                  . send-to--ns-send-items))
                                 ((:supported 
                                 . send-to--open-externally-supported-p)
                                  (:collect 
                                  . send-to--collect-items)
                                  (:send 
                                  . send-to--open-externally)))
  "...")

This hopefully supports your use-case?

>From 86ca5910318a90fb5e8226d2e57883380ab52d9f Mon Sep 17 00:00:00 2001
From: Alvaro Ramirez <[email-masked]>
Date: Sat, 19 Jul 2025 16:08:25 +0100
Subject: [PATCH] Fix send-to on non-macOS platforms and macOS crash on "emacs
 -nw"

* lisp/send-to.el: Both fixes included.
---
 lisp/send-to.el | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/lisp/send-to.el b/lisp/send-to.el
index 064f5ad6645..431ccfc4bb4 100644
--- a/lisp/send-to.el
+++ b/lisp/send-to.el
@@ -40,7 +40,7 @@
 (declare-function dired-get-filename "dired")
 (declare-function dired-get-marked-files "dired")
 (declare-function dired-move-to-filename "dired")
-(defvar shell-command-guess-open) ;; dired-aux
+(declare-function shell-command-do-open "dired-aux")
 
 (defgroup send-to nil
   "Send files or text to external applications or services."
@@ -159,6 +159,7 @@ send-to--resolve-handler
 (defun send-to--ns-supported-p ()
   "Return non-nil for macOS platform supporting send capability."
   (and (featurep 'ns)
+       (display-graphic-p)
        (fboundp 'ns-send-items)))
 
 (defun send-to--ns-send-items (items)
@@ -168,23 +169,17 @@ send-to--ns-send-items
 
 (defun send-to--open-externally-supported-p ()
   "Return non-nil for platforms supporting open externally capability."
-  (unless (boundp 'shell-command-guess-open)
+  (unless (fboundp 'shell-command-do-open)
     (require 'dired-aux))
-  shell-command-guess-open)
+  (fboundp 'shell-command-do-open))
 
 (defun send-to--open-externally (items)
   "Open ITEMS externally (using a non-Emacs application)."
-  (unless (boundp 'shell-command-guess-open)
+  (unless (fboundp 'shell-command-do-open)
     (require 'dired-aux))
   (when (y-or-n-p (format "Open externally: %s ?"
                           (send-to--format-items items)))
-    (dolist (item items)
-      (with-temp-buffer
-        (unless (zerop (call-process
-                        shell-command-guess-open nil (current-buffer) t
-                        (send-to--convert-item-to-filename
-                         item)))
-          (error "%s" (string-trim (buffer-string))))))))
+    (shell-command-do-open items)))
 
 (defun send-to--convert-item-to-filename (item)
   "Convert ITEM to a filename.
--
2.50.0