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.

THX

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:

1 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())
	{
		app.displayInfoMessage("Success");
		return true;
	}
	else
	{
		app.displayErrorMessage("Error: " + shScript.standardError);
		console.log(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

Drafts can only write directly to it’s own container in iCloud Drive

I stumbled onto this thread looking for the same thing as the OP. Is this really true? I’m using MDNotes.app for this now but looking for a replacement since the dev told me he’s pulling the app soon. But MDNotes is somehow able to open/save in any iCloud drive folder (not just its own container). How is this?

Drafts can open and export to any folder, but you generally have to manually select the location each time. Presumably that is how MDnotes is doing it, though some apps do also set up wthe equivalent of folder shortcuts for convenience (e.g. Textastic).

Automated save locations are limited to sandboxed app areas by Apple.

However, I posted a shell script based workaround for automated saves above.