List Action Keyboard Shortcuts Action

Updated 09222025-050556


Meta

Description

Query all configured Action keyboard shortcuts as a sorted, formatted markdown list in a new Draft.

Directory Description

Source

<iframe src=“https://gist.github.com/extratone/879bbbbb13379043b8325580dc8bcea4.pibb" style="width: 95%; height: 500px; border: 0;">

// Drafts Action: List Action Keyboard Shortcuts (Markdown)

function getAllActions() {
    let all = [];
    ActionGroup.getAll().forEach((grp) => (all = all.concat(grp.actions)));
    return all;
}

function parseShortcut(action) {
    try {
        const raw = decodeURIComponent(action.installURL.replace("drafts://action?data=", ""));
        const data = JSON.parse(raw);

        if (!data.keyCommand) return "";

        const kc = data.keyCommand;
        const parts = [];

        // Apple style glyphs
        if (kc.commandKey) parts.push("⌘");
        if (kc.optionKey) parts.push("⌥");
        if (kc.controlKey) parts.push("⌃");
        if (kc.shiftKey) parts.push("⇧");

        if (kc.input && kc.input.length > 0) {
            switch (kc.input) {
                case "#LEFT":
                    parts.push("←");
                    break;
                case "#RIGHT":
                    parts.push("→");
                    break;
                case "#UP":
                    parts.push("↑");
                    break;
                case "#DOWN":
                    parts.push("↓");
                    break;
                case "#TAB":
                    parts.push("⇥");
                    break;
                case "#ESC":
                    parts.push("⎋");
                    break;
                default:
                    parts.push(kc.input);
            }
        }
        return parts.join("");
    } catch (e) {
        return "";
    }
}

const items = [];

getAllActions().forEach((act) => {
    const shortcut = parseShortcut(act);
    if (shortcut) {
        items.push({ title: act.name, keys: shortcut });
    }
});

// sort by title (case-insensitive)
items.sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase()));

const lines = items.map((itm) => `- *${itm.title.replace(/([*_])/g, "\\$1")}* - \`${itm.keys}\``);

const output = lines.join("\n");

// copy to clipboard & pass to template tag
app.setClipboard(output);
draft.setTemplateTag("keylist", output);