Joplin hack!


The CLI client for Joplin is very limited in functionality. It’s good for import, export/backup, and some very simple note-manipulation, but that’s all.

The mobile clients are mostly functional, provided you want all your notes sorted by title, created date, or updated date across all notebooks (per-notebook settings are a concept yet to be implemented on any client). The concept of dragging notes into a specific order is only supported on the desktop client.

…unless you’re willing to cheat, which I am. Using the plugin API and code cribbed from the Combine Notes plugin, I wrote a tiny little plugin that modifies the titles of the selected notes so that they are prefixed with a string of the form “001# ”, replacing any existing prefix. So, if you select all the notes in a folder that you’ve arranged in a custom order, then when they replicate to a mobile client, title-sort will preserve your order.

I’d make it a lot more robust and customizable before publishing it as an official Joplin plugin, but it meets my needs, and if anyone else thinks they’d find it useful, here’s Custom Order Titling.

import joplin from 'api';
import { MenuItemLocation, SettingItemType } from "api/types";

function zeroPadding(number, length) {
  return (Array(length).join('0') + number).slice(-length);
}

joplin.plugins.register({
  onStart: async function() {
    await joplin.commands.register({
      name: "CustomOrderTitling",
      label: "Custom Order Titling",
      execute: async () => {
        const ids = await joplin.workspace.selectedNoteIds();
        const prefixRegexp = /^\d{3}# /;
        if (ids.length > 1) {
          let i = 1;
          for (const noteId of ids) {
            const note = await joplin.data.get(["notes", noteId], {
              fields: [
                "title",
              ],
            });
            let strippedTitle = note.title.replace(prefixRegexp, "");
            const newTitle = zeroPadding(i,3) + "# " + strippedTitle;
            await joplin.data.put(['notes', noteId], null, { title: newTitle });
            i = i + 1;
          }
        }
      },
    });
    await joplin.views.menuItems.create(
      "contextMenuItemconcatCustomOrderTitling",
      "CustomOrderTitling",
      MenuItemLocation.NoteListContextMenu
    );
  },
});

Two caveats:

  1. I believe that the sync works on the complete-note level, so that updating even a single field like title replicates the entire note, but only the metadata and body text, not any attachments.

  2. The order that you build up your selection of notes is the order the plugin will see them in. So, if you were to add them to the selection in random order, then the prefixes will be generated to match.


Comments via Isso

Markdown formatting and simple HTML accepted.

Sometimes you have to double-click to enter text in the form (interaction between Isso and Bootstrap?). Tab is more reliable.