Skip to content

Instantly share code, notes, and snippets.

@craigeley
Last active April 6, 2018 02:39
Show Gist options
  • Save craigeley/aa605c3e984872080907 to your computer and use it in GitHub Desktop.
Save craigeley/aa605c3e984872080907 to your computer and use it in GitHub Desktop.
An Automator action to send edited sidecar Markdown files back to Day One.
if RUBY_VERSION =~ /2.*.*/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
dayone_path = '/path/to/journal.dayone/entries/'
file_path = ARGV[0]
/UUID:\s(?<uuid>.*)/ =~ IO.readlines(file_path)[1]
# Create working plist file
`cp #{dayone_path}#{uuid}.doentry ~/#{uuid}.plist`
# Get new text
content = IO.read(file_path)
content = content.gsub!(/---\nUUID:.*\n---\n/, '')
content = content.gsub!(/\n/, '\n')
# Push changes back to Day One and trash working file
`defaults write ~/#{uuid} "Entry Text" "#{content}"`
`cp ~/#{uuid}.plist #{dayone_path}#{uuid}.doentry`
`rm ~/#{uuid}.plist`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment