Using shortcut to move all my Draft's files to Obsidian


I’m trying to automate the export of my Draft note to obsidian with Shortcut.

I have succeed to create an action that Move my file to obsidian (thanks to this community).

I am using this action : Save in Obsidian Vault | Drafts Directory

Expect I have change 2 parameters:

  • Change to “append” to update the file if it already exists
  • Add “Move to trash” when the action is done so my inbox is always empty

It works when I trigger manually the action.

Now I’m trying to create a shortcut that send ALL my Draft’s note to Obsidian, automatically (the final idea is to trigger this shortcut once a day, when I stop my alarm in the morning for exemple).

I have done some testing so far, and succeed to send multiple Draft’s note to Obsidian with a Shortcut, the only issue is that the action does not trigger the “move to trash” feature when it’s a success.

Is there a way to make it work with the “Trash” feature at the end?

If you are looping through your inbox drafts in Shortcuts, then you could use the “File Draft” action in Shortcuts following your “Run Action on Draft” action in Shortcuts, on the same draft.

Alternatively, you could modify your action in Drafts to include an extra step to explicitly trash the draft. A script action with this should do it for the current draft.

draft.isTrashed = true;

If you want this to work as an automation, you are probably better off doing the work in Shortcuts so it can run in the background.

What you have, I would think would work, but running actions in Drafts requires the app to open, and does not play super well with repeating in a loop like that over many drafts.

If you get the drafts in Shortcuts, and just use Shortcuts file actions to write out the files where you want for Obsidian, you can then use the “File Draft” action in shortcuts to move them to the trash.

1 Like

@sylumer I’m going to test it but will it not delete the Draft file even if the export is not working? I don’t want the file to be delete if the transfer to Obsidian failed to not lost data. (so I can fix it or do it manually later)

@agiletortoise Can I do all the process directly in Draft? Didn’t even know it was possible, I’m going to dig into the idea in the next days. Especially if I can run it on autopilot.

You can write an action in Drafts that queries a workspace, and loops over it’s drafts. You could have a script in Drafts something like the below that is equivalent to what you are trying to do in Shortcuts:

// load your workspace
let workspace = Workspace.find("Obsidian")
// get the drafts in the inbox
let drafts = workspace.query("inbox")
// load the action you want to run
let action = Action.find("Save in Obsidian Vault")
// loop over drafts, queueing the action to run on each:
for (let d of drafts) {
    app.queueAction(action, d)

You could just call that one action to run in Drafts then to process everything in that workspace at once.