1

On MacOS, there are a number of link types which just work for opening things system-wide, for example, rdar://123456789 for opening an issue in the Radar app. These can all be opened with the open command. I'd like Emacs to use open for all types of links, and have open figure out what program to use. Is there a way to do that? I already have browse-url-generic-program set to open, but it doesn't seem to work---clicking on, e.g., [[rdar://123456789]] in Org mode doesn't open it in Radar, it just says "no match for fuzzy expression."

I should specify that I'm not looking for a solution to the local problem of Radar links, but any kind of link that MacOS knows how to handle with open, so [[foo://bar]], where foo is some link type that, if you put it in Safari or another MacOS app, the system knows how to handle it.

3 Answers 3

3

Org mode doesn't know your rdar link, so it simply registers it as a fuzzy-text-search link-type.

You should tell Org mode how to deal with it by defining a new link type:

(org-link-set-parameters "rdar" :follow #'rdar-open)

(defun rdar-open (path _) ; "_" here is the universal prefix argument, you can define different behavior if you like
  (browse-url (concat "rdar:" path)))

See the doc string of the variable org-link-parameters (C-h v org-link-parameters) for details on the allowed keys (like :follow above) and the associated values (functions mostly, like rdar-open above). See also the section on Adding hyperlink types in the manual for a more extended example.

1
  • This is great, and helps with the specific case of Radar links, but I'm really looking for a more general solution in which Emacs can recognize links that MacOS can recognize, such that clicking [[foo://bar]] will look up the URL handler for foo-type links from the system, and use that application, and/or just use open to open all link types. I've updated my question to reflect this.
    – Jonathan
    Jan 31, 2023 at 18:53
0

[This is completely untested - I have no MacOS system to try it on. There are also a lot of links in the chain that need to be intact or else things will just not work].

Try a link like this: [[file+sys:rdar://123456789]]. This should pass the path (i.e. rdar://123456789) to the system application specified in org-file-apps-macos whose default value is:

(defconst org-file-apps-macos
  '((remote . emacs)
    (system . "open %s")
    ("ps.gz"  . "gv %s")
    ("eps.gz" . "gv %s")
    ("dvi"    . "xdvi %s")
    ("fig"    . "xfig %s")
    (t . "open %s"))
  "Default file applications on a macOS system.
The system \"open\" is known as a default, but we use X11 applications
for some files for which the OS does not have a good default.
See `org-file-apps'.")

So if the stars are aligned correctly, it should call open and pass it the "path" i.e. the special MacOS link you specified.

EDIT: I don't think that this will work based on some local tests on Linux, but there are so many twisty passages in the code that I'm not sure that it will fail. Try it and see...

3
  • When I click on [[file+sys:rdar://104575579]] I get error: No such file: /Users/jon/Documents/Org/Roam/rdar:/104575579. It seems it treats file link types as files.
    – Jonathan
    Jan 31, 2023 at 22:33
  • Ah, well - it was worth a try...
    – NickD
    Jan 31, 2023 at 23:00
  • The problem is that org-open-file calls expand-file-name and there seems to be no easy way to avoid it...
    – orgtre
    Mar 7, 2023 at 0:16
0

One way to get a more general solution is to create a link type that actually uses open to follow links:

(with-eval-after-load 'org
  
  (defun org-mac-open (link _)
    (call-process "open" nil 0 nil link))
  
  (org-link-set-parameters "mac" :follow #'org-mac-open))

With this the following example links work as expected for me:

[[mac:dict://test][test (dict)]]
[[mac:spotify:track:687YZan9Gol1UVvbpUSO6Y][song (spotify)]]
[[mac:addressbook://me][me (addressbook)]]
[[mac:maps:q=San+Francisco][San Francisco (maps)]]

These links can for example be inserted using M-x org-insert-link (or C-c C-l by default) and then selecting the mac type.

To get a list of available URL schemes one can run this in terminal: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump URLSchemeBinding. Then one can use a search engine to find out how to use each of them.

A tip is to also add a org-link-make-description-function that is smart about creating descriptions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.