Org Mode custom link: copy to clipboard

| emacs, org

I have a tiny corporation for my consulting. I do all of my own paperwork. I have lots of notes in Org Mode for infrequent tasks like the tax-related paperwork I do once a year. My notes include checklists, links, and Org Babel blocks for calculations. I often need to copy standard text (ex: the name of the company) or parts of the output of my Org Babel blocks (ex: tax collected) so that I can fill in web forms on the Canada Revenue Agency website.

This little snippet makes it easy to copy text for pasting. It defines a custom Org link that starts with copy:. When I follow the link by clicking on it or using C-c C-o (org-open-at-point), it copies the text to the kill ring (which is what Emacs calls the clipboard) so that I can paste it anywhere. For example, [[copy:Hello world]] becomes a link to copy "Hello world". Copying means never having to worry about typos or accidentally selecting only part of the text.

(use-package org
   :follow (lambda (link) (kill-new link))
   :export (lambda (_ desc &rest _) desc)))

I can use these links as part of my checklist so that I can quickly fill in things like my business name and other details. I can put sensitive information like my social insurance number in a GPG-encrypted file. (Just set up your GPG keys and end a filename with .gpg, and Emacs will take care of transparently encrypting and decrypting the file.)

I can also export those links as part of my Org Babel output. For example, the following code calculates the numbers I need to fill in a T5 form for the other-than-eligible dividends that I issue myself according to the T5 instructions from the CRA.

(let* ((box-10 1234) ; fake number for demo
       (box-11 (* 1.15 box-10))
       (box-12 (* 0.090301 box-11)))
  `((box-10 ,(format "[[copy:%.2f][%.2f]]" box-10 box-10))
    (box-11 ,(format "[[copy:%.2f][%.2f]]" box-11 box-11))
    (box-12 ,(format "[[copy:%.2f][%.2f]]" box-12 box-12))))
box-10 1234.00
box-11 1419.10
box-12 128.15

On my computer, the numbers become links that I can click and copy. Another little shortcut thanks to Emacs and Org Mode!

View org source for this post
This is part of my Emacs configuration.
You can comment with Disqus or you can e-mail me at