oca icon indicating copy to clipboard operation
oca copied to clipboard

Org Capture Anywhere

#+TITLE: oca

[[tag][file:https://img.shields.io/github/v/tag/lepisma/oca.svg?style=flat-square]]

Org Capture Anywhere (~oca~) allows you to use [[https://orgmode.org/manual/Capture.html][Org Capture]] for capturing items /anywhere/.

Many times I need to capture structured text items that have to go in places that are not Org mode files. For example, to create tasks in [[https://www.atlassian.com/software/jira][Jira]] or [[https://trello.com/][Trello]] or adding an event on Google Calendar. This package provides simple functions to extend Org Capture's final destination.

Once installed, call ~oca-setup~ for setting up capture hooks. Then define your capture workflow by writing a template and specifying a /push/ function. The push function takes AST of captured Org item via ~org-element~ API and does whatever it wants with it.

Here is an example to log lines in an SQLite database. We first define a push function that takes a headline entry and pushes the title to our database.

#+begin_src emacs-lisp (defun oca-push-my-db (element) (let ((text (org-element-property :raw-value element))) (call-process "sqlite3" nil nil nil "db.sqlite3" (format "insert into data (line) values ("%s")" text)))) #+end_src

#+RESULTS: : oca-push-my-db

Then write a capture template using ~oca-visit~ and the push function defined above.

#+begin_src emacs-lisp (setq org-capture-templates '(("s" "Capture to SQLite" entry (function (lambda () (oca-visit #'oca-push-my-db))) "* %?"))) #+end_src

Now capturing items using ~C-c c s~ will put the line in the database.