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.

Thank you for providing this information @agiletortoise. I stumbled across your post while I was looking for a way to export entries from Drafts into my Obsidian vault on DropBox. I was mostly successful, but have one issue to overcome.

When an entry is exported from Drafts into the Obsidian vault on DropBox the first line is made the title, which is what I need. However, in Drafts, when I leave a blank line after the first line (which becomes the title in Obsidian) there is also a blank line before the body of the entry in Obsidian.

What I want to do in Drafts is have a blank line between the first line and the body of the text entry, but have this blank line deleted from what is imported into Obsidian. I am making sense?

I would like to do this so that in Drafts I can separate the title of an entry from the body of the text. Having the space works visually for me.

What do I need to do to achieve this?

I look forward to your guidance. I am a total newbie to this.

Cheers! from Japan

Change the template setting from [[body]] to [[line|3..]]. This will skip lines 1 and 2, and output line 3 onwards as the file content.

Wow! Thank you so much @sylumer. It worked exactly as I wanted it to. Thanks again!!!

I have the Obsidian Synch feature so I was wondering how I could send a drafts in iOS to a non-iCloud file on my iPhone. Is that possible?

Assuming you mean from the Mac to iOS (this is a Mac thread), try this:

For iOS only, read this thread.

For new questions, do remember to search first and then post a new topic; it makes it easier to find and associate questions and answers that way.

1 Like

Thanks, I reposted on iOS thread.