UP | HOME

Print org-mode agenda to a file

Table of Contents

1 Exporting agenda to HTML

To export your agenda to a file, use org-agenda-write function, the parameter will be a file name.

Depends on the extension of the file, Emacs will write your agenda to html, pdf, ps or plain text file.

(progn
  (org-agenda nil "c")
  (org-agenda-write "~/.agenda.html"))

So, if you want to automate it, use crontab. The following snippet setup a cronjob that export your agenda every 15 minutes:

*/15 * * * * emacs --batch --load ~/.emacs.d/init.el --eval "(progn (org-agenda nil \"c\") (org-agenda-write \"~/.agenda.html\"))"

2 Making an app to display agenda

Now that I have the .agenda.html file, I want to create a GUI application that can display this file, so I can open it up when I need, and close it when I'm done.

There are a lot of option to create GUI app, since I'm on a macOS machine, and already have Rust installed, I'll go with an old solution I have: https://github.com/huytd/kanban-app

Just simply modify the main.rs so it can read the file directly from ~/.agenda.html and display it in a new window:

extern crate web_view;

use web_view::*;
use std::io::prelude::*;
use std::fs::File;

fn main() {
    let size = (750, 500);
    let resizable = true;
    let debug = false;
    let titlebar_transparent = true;
    let frontend_cb = |_webview: &mut _, _arg: &_, _userdata: &mut _| {};
    let userdata = ();

    let mut file = File::open("/Users/huy/.agenda.html").expect("Unable to open the file");
    let mut contents = String::new();
    file.read_to_string(&mut contents).expect("Unable to read the file");

    let html = format!(r#"<style>{css}</style>{html}"#,
                       css = "* { font-family: MonacoB2, Monaco, Menlo; monospace; font-size: 14px; cursor: default; } html, body { background: #212121; } .org-tag { background: #444; opacity: 0.5; }",
                       html = contents);

    run(
        "",
        Content::Html(html),
        Some(size),
        resizable,
        debug,
        titlebar_transparent,
        move |mut webview| {
            webview.set_background_color(0.11, 0.12, 0.13, 1.0);
        },
        frontend_cb,
        userdata
    );
}

Then I'll just need config the bundler in Cargo.toml:

[package.metadata.bundle]
name = "OrgAgenda"
identifier = "com.huy.agendaapp"
version = "1.0.0"
resources = []
copyright = "Copyright (c) Huy Tran 2018. All rights reserved."
short_description = "OrgMode Agenda"
long_description = "OrgMode Agenda"

Finally, create the actual application:

cargo bundle --release

VoilĂ !

Date: 2019-01-04 Fri 00:00

Author: Huy Tran

Created: 2019-04-22 Mon 14:41