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]]
[[draft]]
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.
http://agiletortoise.com/blog/2013/03/27/mimic-drafts-append-to-dropbox-using-alfred-on-a-mac/
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 = "#{Time.now.strftime(’#### %Y-%m-%d (%a) @ %I:%M %p’)}
\n#{s}
—"
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”
end