Posts in the Tools category:

Keeping notes with Orgzly and Nextcloud

in Tools by evan power
Tags: , , , , ,

I tend to keep notes for non-work stuff on my phone using the Orgzly Android app. It stores notes in a plain-text format called org-mode. I have it set up to sync my notes to a Nextcloud server via WebDAV. This works nicely, but Nextcloud by default doesn't allow me to view or edit my notes through its web interface. With a little tinkering, though I was able to change that. This post is mostly to record these steps for myself, but you never know, someone else might find them useful.

Setting up WebDAV in Orgzly

First, from the Nextcloud web interface create a folder in your Nextcloud instance called "notes". Then on your phone open Orgzly's settings and select "Sync" and then "Repositories". Press the "+" button at the top right to add a new sync location. You will be prompted to select either "WebDAV" or "Directory". Select "WebDav". You will then see fields for a URL, a username, and a password. In the URL field enter "[Your Nextcloud Instance's URL]/remote.php/dav/files/[your Nextcloud user name]/notes". In the username and password fields enter your Nextcloud username and password. Go to one of your notebooks in Orgzly and select "sync" from the menu. Your Orgzly notes should synchronize to the "notes" folder on your Nextcloud instance.

Configure Nextcloud to Edit .org Files

Having your notes in your Nextcloud is handy for backup purposes, but by default Nextcloud's web interface can't view or edit .org files. Changing this requires shell access to the machine that your Nextcloud instance is running on and permissions to modify the Nextcloud configuration.

First install the Plain Text Editor app through the Nextcloud web interface. This will add a "Edit in plain text editor" entry to the right click menu for certain file types in the Nextcloud web interface's file browser. Unfortunately .org is not one of the types of file that the plain text editor app supports out of the box. Fortunately, the Nexcloud developers implemented a nice feature called [Mimetype Mapping] that allows us to tell Nextcloud to treat .org files as plain text files. SSH into the server that hosts your Nextcloud instance and navigate to the directory that Nextcloud is installed in. (On Debian-like operating systems this could be something like /var/www/nextcloud/.) In the "config" sub-folder make a file called "mimetypemapping.json" that contains the following:

{
  "org": ["text/plain"]
}

Now we will have to tell Nextcloud to update its database of MIME types and files. From the Nextcloud installation directory run the following commands. These commands assume that the username that Nexcloud runs under is "www-data" if this is not the case on your system replace "www-data" with the username that runs Nextcloud.

sudo -u www-data php occ maintenance:mimetype:update-js

sudo -u www-data php occ files:scan --all

You should now be able to right click on .org files in Nextcloud's web iterface and edit them as plain text files. There will not be any fancy highlighting or formatting because Nexcloud has no understanding of the org-mode syntax, but it's good enough for quick edits.

These instructions were written for 18.0.6 and Orgzly 1.8.3. It looks like in version 19 of Nextcloud the "mimetypemapping.json" file should be named "mimetypealiases.json" instead.