Org-Ql From the Command Line

Most of my tasks and projects are organized using org-mode. I was looking for a way to query them from an LLM and, rather than recreate an index and a database, I can use what I normally use, org-ql using emacs in batch mode.

Here’s how to run org-ql from the command line.

emacs --batch -l $HOME/.emacs.d/init.el --eval "(message (with-output-to-string (princ (mapconcat 'identity (org-ql-select (org-agenda-files) '(todo \"WAITING\") :action '(org-get-heading t t)) \"\n\"))))"

Each matching result will be printed out on a newline. This can then be used for further processing by capturing stdout.