[Solved] Copy notes to Obsidian folder

How can I copy a draft into an Obsidian folder (residing in iCloud) in markdown/.md extension? Is there an action for this?

As workaround I use Ulysses with external file access, but for quick notes it is a bit clunky.


Drafts can only write directly to it’s own container in iCloud Drive (the “Drafts” folder).

You can use an Export action step to be prompted where to save the file, and select your existing Obsidian folder, or you could move your Obsidian folder inside the “Drafts” folder, then be able to configure File actions steps to write into the vault without any further prompting.

With limited testing, it appears you have to write with .md extensions for Obsidian to recognize the files. An example File step configuration might look something like:

@Fulcanelli does this solve your problem

Perfect! All I needed.

THX very much

Just to throw another option into consideration.

I’m assuming that Obsidian is in use on a Mac (I’ve not seen an iOS/iPadOS version as yet) alongside Drafts in this particular case.

While the JavaScript run from inside of Drafts is sandboxed, the same isn’t true in terms of a shell script. This setup seems to work for me in my testing.

Set-up a script step in an action with the following.

function exportFile(p_strDestinationPath)
	// Write a file to the Drafts area
	let fmLocal = FileManager.createCloud();
	fmLocal.writeString("/movethisfile.txt", draft.content);

	// Set up a shell script to move the file out of the Drafts area
	let strScript = `#!/bin/zsh
	mv "$HOME/Library/Mobile Documents/iCloud~com~agiletortoise~Drafts5/Documents/movethisfile.txt" "${p_strDestinationPath}"
	let shScript = ShellScript.create(strScript);

	// Run the script
	if (shScript.execute())
		return true;
		app.displayErrorMessage("Error: " + shScript.standardError);
		return false;

exportFile("$HOME/Library/Mobile Documents/com~apple~CloudDocs/Temp/test_output_from_drafts.md");

Here the draft content is effectively placed into a file called test_output_from_drafts.md, within my Temp directory in iCloud, but it could be a file anywhere accessible in the file system on my Mac.

What actually happens is that Drafts outputs the file as normal, within its sandbox, and then the shell script moves it to its final destination.

1 Like