Audio Record Hotkey

Use case or problem

First of all, I LOVE Obsidian. So much so I’d like to make it slightly better. :grin:

So, I create audio memos on a daily basis. As someone who has a limited Hotkey budget (lots of plugins and limited memory), it would be a nice hotkey saver to use the same hotkey to start and stop (toggle) the recording.

And unfortunately this doesn’t work:

:cry:

Proposed solution

My proposed solution is to create a new hotkey option to Toggle the Audio Record with a single hotkey. :joy: Something like “Audio recorder: Toggle recording audio”

Current workaround (optional)

The only workaround that I can think of is to have a key combination modifier, something like Ctrl+R (on) and Ctrl+Shift+R (off). :neutral_face:

3 Likes

This is a problem for me as well. On mobile it requires two separate buttons in the toolbar to perform the functionality of the single start/stop recording button on desktop

1 Like

Came here to say this as well. In addition to “limited hotkey budget”, it’s just easier to remember one hotkey instead of two.

Using the CodeScript Toolkit plugin, you can put a .js file in whatever folder you set as the “Invocable scripts folder.” Then, you can assign a hotkey to that script.

This script toggles the audio recorder.

exports.invoke = async (app) => {
  function isCommandAvailable(commandId) {
    const cmd = app.commands.commands[commandId];
    if (!cmd || typeof cmd.checkCallback !== 'function') {
      return false;
    }
    try {
      return cmd.checkCallback(() => {}, true);
    } catch {
      return false;
    }
  };

  if (isCommandAvailable('audio-recorder:start')) {
    app.commands.executeCommandById('audio-recorder:start');
    new Notice('🔴 Recording started');
    return;
  }
  if (isCommandAvailable('audio-recorder:stop')) {
    app.commands.executeCommandById('audio-recorder:stop');
    new Notice('⏹️ Recording stopped');
    return;
  }
};

It will check if the “Audio recorder: Start recording audio” command is available, and, if it is, run that command. The command is no longer accessible while recording audio, but “Audio recorder: Stop recording audio” is… So, when you run the script again, it’ll run that instead.

Oh, actually, figured out an even simpler way. app.internalPlugins.plugins["audio-recorder"].instance.recording returns a true/false. True if currently recording, false if not.

exports.invoke = async (app) => {
  if (app.internalPlugins.plugins["audio-recorder"].instance.recording) {
    app.commands.executeCommandById('audio-recorder:stop');
    new Notice('⏹️ Recording stopped');
  } else {
    app.commands.executeCommandById('audio-recorder:start');
    new Notice('🔴 Recording started');
  }
};
1 Like