I use Emacs and Org mode extensively for managing notes, documents, and related assets. One recurring friction point in my workflow has been accessing Org attachments outside of Emacs, particularly when I need to copy files into other tools such as PowerPoint, Word, or other document systems.
Org mode’s attachment system (org-attach) is excellent at managing and organising files, but its interaction model is primarily Emacs-centric (via Dired). Sometimes, however, the fastest path is to open the attachment directory directly in the operating system’s file explorer.
This post documents a small helper function I wrote to close that gap.
The use case
From within an Org heading that uses org-attach, I want to:
- Locate the attachment directory for the current heading
- Create it if it does not yet exist
- Open that directory in the system’s default file explorer
This is particularly useful when:
- Copying attachments into presentations or reports
- Drag-and-dropping files into other applications
- Browsing attachments using native OS previews
The function
The function below works across macOS, Windows, and Linux, using OS-native mechanisms to open the directory.
(defun tj/open-in-explorer ()
"Open the current Org heading's attachment directory in the system file explorer."
(interactive)
(require 'org-attach)
(let ((dir (org-attach-dir t)))
(unless dir
(user-error "No attachment directory for this heading"))
(setq dir (file-truename dir))
(when (file-remote-p dir)
(user-error "Cannot open remote attachment directory locally"))
(cond
((eq system-type 'darwin)
(start-process "tj-open-explorer" nil "open" dir))
((eq system-type 'windows-nt)
(w32-shell-execute "open" dir))
(t
(start-process "tj-open-explorer" nil "xdg-open" dir)))))
How it works
-
org-attach-dirresolves the correct attachment directory for the current heading and creates it if necessary. -
Platform-specific commands are used to open the directory:
- macOS:
open - Windows:
w32-shell-execute - Linux:
xdg-open
- macOS:
-
Remote (TRAMP) paths are explicitly rejected, since they cannot be opened locally.
Why this approach
While it is possible to navigate attachments via Dired, opening the directory in the system file explorer is often faster and better suited to tasks that involve external tools. This small helper preserves Org mode as the canonical source of truth while still integrating smoothly with the surrounding OS environment. As always - bend emacs to your needs, not your workflow it its.1
Possible extensions
Some ideas for future refinements:
- Reveal a specific attachment file rather than just the directory
- Add a transient or hydra menu for common attachment actions
- Enable use from Org Agenda buffers
- Integrate with clipboard or sharing workflows
Small functions like this help keep my workflow text-first and structured, while remaining pragmatic when interacting with non-Emacs tools.
-
I have found that it is always worth checking that there isn’t a better way that is built in - I’m confident there isn’t however - do correct me if this is not the case. ↩︎