# DataviewJS Snippet Showcase

**URL:** <https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847>\
**Category:** Workflows & Templates\
**Tags:** dataview\
**Created:** [May 8, 2021, 8:02am UTC](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847 "2021-05-08T08:02:55Z")\
**Posts on this page:** 1\
**Showing post:** 37

<div class="post-metadata">

**Author:** ![Moonbase59](https://forum.obsidian.md/user_avatar/forum.obsidian.md/moonbase59/32/13648_2.png) [@Moonbase59](https://forum.obsidian.md/u/Moonbase59)\
**Post date:** [July 20, 2021, 2:11pm UTC](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847/37 "2021-07-20T14:11:06Z")

</div>

## Obsidian Command and Hotkey List (new version)

In continuation of [the older post](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847/13), here is a new version of the _Obsidian Command List_.

Features:

- Commands **sorted by assigned hotkey**
- Commands **sorted by internal Command ID**
- Command names shown in the **language Obsidian is _currently set to_** —ideal for multi-lingual people who switch often, and for users of the _[Buttons](https://github.com/shabegom/buttons)_, _[Obsidian Leaflet](https://github.com/valentine195/obsidian-leaflet-plugin)_, _[Command URI](https://github.com/deathau/command-uri-obsidian)_ and _[Advanced Obsidian URI](https://github.com/Vinzent03/obsidian-advanced-uri)_ plugins.
- Now shows the **_current_ hotkey settings** , not just the defaults.
- **Modified hotkeys** (different from the default setting) are now shown **bolded**.

Here’s what it looks like:

 ![Knowledgebase - Obsidian v0.12.10_049](https://forum.obsidian.md/uploads/default/original/3X/6/5/65d882b69e30e45e5715c3da75e95a7bb570f4b1.png)

 ![Knowledgebase - Obsidian v0.12.10_050](https://forum.obsidian.md/uploads/default/original/3X/4/0/40344b9e24238d7dec2a65fbc1c1a7600f697012.png)

### Complete note showing both versions:

Just copy-paste into a new note and try it out:

````auto
---
date: 2021-06-26
author: Matthias C. Hormann a.k.a. Moonbase59
tags: [obsidian, commands, hotkeys]
---

# Obsidian Command List

This shows the currently active commands and defined hotkeys. Command _names_ are localized to whatever language you’ve set Obsidian to use (the same as used in the Command Palette).

Check the code to see how I’ve done this using _Dataview JS_.

### Commands sorted by assigned hotkey

```dataviewjs

const getNestedObject = (nestedObj, pathArr) => {
    return pathArr.reduce((obj, key) =>
        (obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj);
}

function hilite(keys, how) {
    // need to check if existing key combo is overridden by undefining it
    if (keys && keys[1][0] !== undefined) {
        return how + keys.flat(2).join('+').replace('Mod', 'Ctrl') + how;
    } else {
        return how + '–' + how;
    }
}

function getHotkey(arr, highlight=true) {
    let hi = highlight ? '**' : '';
    let defkeys = arr.hotkeys ? [[getNestedObject(arr.hotkeys, [0, 'modifiers'])],
    [getNestedObject(arr.hotkeys, [0, 'key'])]] : undefined;
    let ck = app.hotkeyManager.customKeys[arr.id];
    var hotkeys = ck ? [[getNestedObject(ck, [0, 'modifiers'])], [getNestedObject(ck, [0, 'key'])]] : undefined;
    return hotkeys ? hilite(hotkeys, hi) : hilite(defkeys, '');
}

let cmds = dv.array(Object.entries(app.commands.commands))
    .where(v => getHotkey(v[1]) != '–')
    .sort(v => v[1].id, 'asc')
    .sort(v => getHotkey(v[1], false), 'asc');

dv.paragraph(cmds.length + " commands with assigned hotkeys; " +
    "non-default hotkeys <strong>bolded</strong>.<br><br>");

dv.table(["Command ID", "Name in current locale", "Hotkeys"],
  cmds.map(v => [
    v[1].id,
    v[1].name,
    getHotkey(v[1]),
    ])
  );
```

### Commands sorted by Command ID

```dataviewjs

const getNestedObject = (nestedObj, pathArr) => {
    return pathArr.reduce((obj, key) =>
        (obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj);
}

function hilite(keys, how) {
    // need to check if existing key combo is overridden by undefining it
    if (keys && keys[1][0] !== undefined) {
        return how + keys.flat(2).join('+').replace('Mod', 'Ctrl') + how;
    } else {
        return how + '–' + how;
    }
}

function getHotkey(arr, highlight=true) {
    let hi = highlight ? '**' : '';
    let defkeys = arr.hotkeys ? [[getNestedObject(arr.hotkeys, [0, 'modifiers'])],
    [getNestedObject(arr.hotkeys, [0, 'key'])]] : undefined;
    let ck = app.hotkeyManager.customKeys[arr.id];
    var hotkeys = ck ? [[getNestedObject(ck, [0, 'modifiers'])], [getNestedObject(ck, [0, 'key'])]] : undefined;
    return hotkeys ? hilite(hotkeys, hi) : hilite(defkeys, '');
}

let cmds = dv.array(Object.entries(app.commands.commands))
    .sort(v => v[1].id, 'asc');

dv.paragraph(cmds.length + " commands currently enabled; " +
    "non-default hotkeys <strong>bolded</strong>.<br><br>");

dv.table(["Command ID", "Name in current locale", "Hotkeys"],
  cmds.map(v => [
    v[1].id,
    v[1].name,
    getHotkey(v[1]),
    ])
  );
```

````

Enjoy.

---

_[View the full topic](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847)._
