28

I'd like to have a link like

[[file:~/projects][Projects]]

open directly in Dired rather than Finder (I'm on a Mac), which is what it does now. Is there a way? (Of course there's a way. It's Emacs.)

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
JohnJ
  • 507
  • 4
  • 10
  • Do you want `file:` links to open in diredit, or would you maybe like to add a new link type (such as `diredit:`) to org mode? – nanny Mar 31 '15 at 15:28
  • Either would be OK, I think. – JohnJ Mar 31 '15 at 15:44
  • You can read how to add a hyperlink type in the org manual here: http://orgmode.org/manual/Adding-hyperlink-types.html When I get the chance, I'll put together a proper answer for you. – nanny Mar 31 '15 at 15:59
  • Maybe it's just me, but what's "diredit"? The built-in directory editor is called [Dired](https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html), so it might just be a typo? If it's an add-on package, it would be great if you could add an appropriate link to your question. – itsjeyd Apr 10 '15 at 12:57
  • @itsjeyd - yep, typo, fixed. thanks! – JohnJ Apr 10 '15 at 13:01
  • 1
    No problem :) Have you tried opening `[[file:~/projects][Projects]]` in vanilla Emacs (launched via `emacs -Q`)? I'm on Linux, and `org-mode` opens directory links in Dired by default. I don't see why the default behavior should be different for OS X. – itsjeyd Apr 10 '15 at 13:12
  • Have not; Emacs on OS X is packaged as an app (i.e., no `-Q` option on command line). At any rate, my use case is for the full app -- but it's good to know the behavior on Linux now. – JohnJ Apr 10 '15 at 13:48
  • 1
    @JohnJ Just FYI you can type `open -a Emacs.app --args -Q` on the command line on OS X – deprecated Apr 15 '15 at 03:01

3 Answers3

28

There are (at least) two ways. First, typing C-u C-c C-o on a link should force it to be opened in emacs, rather than in an external app. Second, you can permanently override the default behavior by adding an entry to the variable org-file-apps:

(add-to-list 'org-file-apps '(directory . emacs))

which tells org-mode to use dired for all directory links. Alternatively, you could use customize-variable to achieve the same.

The reason that the default behavior is different between OS X and Linux is that org-file-apps-default-macosx contains a fall-through entry (t . "open %s")

deprecated
  • 2,775
  • 14
  • 15
27

You can modify the link description as follows :

     [[file+emacs:~/projects][Projects]]

It will open the link in Emacs with typing C-c C-o.

Lompik
  • 1,214
  • 10
  • 11
  • 3
    FYI: it works but when `M-x org-lint` it shows `Deprecated "file+emacs" link type`. org-version 9.2.6 – junnu Oct 10 '19 at 13:22
0

On Windows, with a link like this:

[[file:~/projects][Projects]]

Left mouse click opens the directory in File Explorer.

Right mouse click opens the directory in dired.

dharmatech
  • 1,212
  • 7
  • 19