Make an Alfred Dropbox action work as per Drafts action

I have a Drafts action - just like many on here do I would expect - to add an entry to a log file on Dropbox. I use the template below and it works as expected.

[[created]] ([[created|%a]]) @ [[created|%I:%M %p]]


So based on the above, the file would run as follows; date, entry, blank line, —, date etc.

2019-07-15 (Mon) @ 04:45 PM

Entry from Drafts goes here

2019-07-15 (Mon) @ 04:45 PM

Next one from Drafts goes here

Now I’d also like to ‘fire’ an entry to the same text file using Alfred on the Mac. I’ve tried to ‘adapt,’ this Alfred Ruby Workflow from the @agiletortoise blog to make it work, so it adheres to the same formatting principles as outlined as per above. Here is a link to the original blog post.

As ever, when I say, ‘adapt,’ I really mean stab wildly at the keyboard in the hope that I’ll get the desired result. This rarely happens, which continues to amaze me.

So although I’ve got the general, date/entry/blank line/—, working, I’m running into issues whereby, the entry from Alfred will sometimes continue on, on the same line as ‘—’. I’ll also sometimes get, 2 blank lines after the ‘—’ when making an entry from Drafts after one from Alfred.

So, instead of me wittering on, I’m just hoping that someone who actually knows what they are on about, could ‘correct’ this Ruby script below so that, irrespective of me sending an entry from Drafts or Alfred, the text file keeps flowing nicely, in an uninterrupted format. Here’s my butchery to date. Cheers in advance.

grab input text

s = “{query}”

create insert value in template with timestamp

tmp = "#{’#### %Y-%m-%d (%a) @ %I:%M %p’)}


path to file you wish to append…

folder path must exist, file will be created if it doesn’t

f = File.expand_path("~/Dropbox/PlainText/scratch_pad.txt")

open file in append mode and add the string

open(f, ‘a’) do |f|
f.puts tmp
f.puts “\n”

Ruby’s not a language I’ve coded in, but give this a try:

s = "{query}"
tmp = "#{'#### %Y-%m-%d (%a) @ %I:%M %p')}\n#{s}\n\n—\n"
f = File.expand_path("~/Dropbox/PlainText/scratch_pad.txt")
open(f, 'a') do |f|
	f.puts tmp
	f.puts "\n"

Also, when posting code I’d recommend wrapping it in triple back ticks. Some oft your quotation marks were off and the comment lines were being (correctly) interpreted as Markdown header syntax.

I gave this a quick try and it gave me consistent results, but do keep in mind if when you are adding Draft content if you have or don’t have a trailing new line. Modify your (iOS only for now) Drafts action accordingly to check for this and apply consistently.

Let us know if this works and if it doesn’t, provide some examples we can retest the behaviour with along with a clear demonstration of the expected output.

Many thanks for your efforts on this. I can’t get the Mac and Drafts inputs to flow as desired in the same text file. I think I’ll leave it as is, as in the scheme of things, there are bigger fish to fry. Thanks again for your help.

When actions arrived on the Mac for Drafts, consider consolidating to a single write “script”. I’m thinking the best option may be to call the Drafts action via URL scheme from Alfred, passing in the query as the text parameter.