Skip to content

Instantly share code, notes, and snippets.

@craigeley
Last active April 6, 2018 02:34
Show Gist options
  • Save craigeley/adfe870a2fae8bd17f8b to your computer and use it in GitHub Desktop.
Save craigeley/adfe870a2fae8bd17f8b to your computer and use it in GitHub Desktop.
When run with Hazel, this script takes a Day One file and creates a sidecar Markdown file and an alias to that file. When the Day One entry is modified, so is the Markdown file, even if it is moved and/or renamed.
#!/usr/local/bin/ruby
require 'plist'
# Fix encoding errors
if RUBY_VERSION =~ /2.2/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
## Change the next line so it points to your Day One file
dayone_path = '/path/to/DayOneFile.dayone/entries/'
# Get Day One file and parse it as a plist
file_path = ARGV[0]
result = Plist::parse_xml(file_path)
uuid = result['UUID']
alias_path = "#{dayone_path}/#{uuid}.md"
# If alias already exists, update the markdown file
if File.exist?(alias_path)
text = result['Entry Text']
content = "---\nUUID:\s#{uuid}\n---\n#{text}"
path = %x{ osascript <<APPLESCRIPT
tell application "Finder"
set theItem to (POSIX file "#{dayone_path}/#{uuid}.md") as alias
if the kind of theItem is "alias" then
return the posix path of ((original item of theItem) as text)
end if
end tell
APPLESCRIPT}
path = path.chomp!
f = File.open(path, 'w+') {|f| f.write("#{content}") }
# If alias does not exist, create it as well as the Markdown file
else
text = result['Entry Text']
format = "---\nUUID:\s#{uuid}\n---\n#{text}"
mark = "~/Desktop/#{uuid}.md"
f = File.open(mark, 'w+') {|f| f.write("#{format}") }
%x{ osascript <<APPLESCRIPT
tell application "Finder"
make new alias to file (POSIX file "#{mark}") at (POSIX file "#{dayone_path}")
end tell
APPLESCRIPT}
end
Copy link

ghost commented Nov 25, 2015

Hi I'm not well versed in Ruby any Idea how to get around this issue?

/usr/local/lib/ruby/gems/2.2.0/gems/plist-3.1.0/lib/plist/parser.rb:105:in parse': Unimplemented element (RuntimeError) from /usr/local/lib/ruby/gems/2.2.0/gems/plist-3.1.0/lib/plist/parser.rb:29:inparse_xml'
from /Users/marty/dotscripts/scripts/dayone_to_markdown.rb:16:in `

'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment