Get current selected card id in canvas

Hi,

@Tekashi’s code snippet looks very useful to me. :slight_smile:
But, unfortunately, I don’t know where to run it from.

const canvasView = this.app.workspace.getActiveViewOfType(ItemView);
if (canvasView?.getViewType() !== 'canvas') return;
const canvas = (canvasView as any).canvas;
const selection: any = Array.from(canvas.selection);

Could anyone, please, tell me where to store this script and how to launch it from within Obsidian.
Sorry, I’m very new to Obsidian and just trying to dive into the world of plugins, commands and scripting.

Do I need to create a plugin to be able to run this code or is there a “lighter” way to run this code?

Info:
My final goal is to write a script that gets the images that are selected within a canvas (multiple files) and to select them in the navigation view (in order to be able yo bulk move them from there).

I created a feature request for this as well here:

But, maybe this could be done faster via scripting.

1 Like