Help with Minor Tweak to Drafts Action

I have a Drafts Action “Markdown to Notes” for sending a Drafts note to Apple Notes as HTML. I was able to edit the script by correcting the Note to be used in the action. That works fine. My problem is that the text that is sent from Drafts to Notes does not insert a paragraph break. I need to edit the script so that the paragraph breaks are inserted when exported to Notes. I know this is simple but I have no coding training.

Screenshot of text in Drafts

Output in Notes

Drafts Action Script
let method = “execute”;
let script = on execute(bodyHTML) tell application "Notes" activate tell account "iCloud" make new note at folder "Notes" with properties {body:bodyHTML} end tell end tell end execute;

let html = draft.processTemplate(`

body { font-size: 15pt; } %%[[draft]]%% `);

let runner = AppleScript.create(script);
if (runner.execute(method, [html])) {
//
}
else {
alert(runner.lastError);
}

What do I need to change and where? Thanks!

Interesting. I haven’t worked with AppleScript for a while, and I’m not on macOS often these days, so can’t offer much help, but I’m assuming that this is something to do with the way the html is being rendered from the markdown? Is there any way to view the html output before you send to Notes?

Your action also seems to be missing some html tags… try:

let method = "execute";
let script = `on execute(bodyHTML)
	tell application "Notes"
		activate
		tell account "iCloud"
			make new note at folder "Notes" with properties {body:bodyHTML}
		end tell
	end tell
end execute`;

let html = draft.processTemplate(`<html>
<head>
<style>
body { font-size: 15pt; }
p {
  /* line-height: 32px;   within paragraph— uncomment and experiment with as required */
  margin-bottom: 30px; /* between paragraphs */
  }

</style>
</head>
<body>
%%[[draft]]%%
</body>
</html>`);

let runner = AppleScript.create(script);
if (runner.execute(method, [html])) {
	//
}
else {
	alert(runner.lastError);
} 

CSS isn’t my forté, so buyer beware!

I “get what I pay for!” :joy: I’ll give this a try. Worse case, I delete and re-install the action in Drafts.

Thanks for the revisions. I replaced the original script with yours. The good news–nothing broke. :grinning: The bad news, nothing changed. :grinning:

Because I have no coding experience I don’t know what is missing but I’d think it is a simple “statement” to insert a lines/paragraphs.

At any rate, I do appreciate your kind assistance!

Hm. Curiosity engaged…

Yes, it’s possible to script something to replace your paragraph break (in this case, I’m assuming that would be \n\n in a regex replace statement) with an appropriate html paragraph break, but that sounds like more work than you should have to do for this.

Just so I know: what happens if you insert a single space in the empty line between the paragraphs in your Drafts note?

I tired that. In fact I even inserted two paragraphs but there are no line or paragraph breaks when the text is sent to Notes.

I think that there is an easier way.

I have a Draft Action that calls an iOS shortcut to send the contents to Notes.
It keeps line breaks, paragraphs, bullets, and other formatting (it probably misses something) – but works for my very simple needs.

Originally, it is called ‘Create note in Notes’ and is described on the Drafts Community Forum (by agiletortoise).
Create note in Notes

I don’t program, so this had to have been simple to install.

1 Like

Darn it! I just cranked up my MacBook to take a further look. Came up with this:

let method = "execute";
let script = `on execute(bodyHTML)
	tell application "Notes"
		activate
		tell account "iCloud"
			make new note at folder "Notes" with properties {body:bodyHTML}
		end tell
	end tell
end execute`;

let dContent = draft.processTemplate(`%%[[draft]]%%`).replaceAll("\n\n","<br>");

let html = `<html>
<head>
<style>
body { font-size: 15pt; }
</style>
</head>
<body>`
+ dContent +
`</body>
</html>`;

let runner = AppleScript.create(script);
if (runner.execute(method, [html])) {
	//
}
else {
	alert(runner.lastError);
}

It’s pretty much what we were talking about— same script, with a little adjustment to replace empty lines with html <br> tags.

@Osopolar : the script we’ve been tweaking in this thread is actually from the same page you posted a link to! The version you’ve referenced was originally iOS only, though I guess it works cross platform now Shortcuts runs on macOS? The above might still be useful for anyone on an older release…

Either way, hope you’re sorted now, @Bmosbacker :wink:

@jsamlarose That worked perfectly! Thanks! I’d buy you a cup of coffee if I could figure out a way to do so online using Apple Pay! Thanks again.

1 Like