Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env ruby
# Based on everwatch.rb by Brett Terpstra, 2011, a 2013 update by spetschu, and a 2014 update by regedor
# Write in Markdown in Evernote and Backup your Markdown files in Dropbox
# Uncomment the following lines if you are having encoding problems in OS X
# if RUBY_VERSION =~ /2.0.0/
# Encoding.default_external = Encoding::UTF_8
# Encoding.default_internal = Encoding::UTF_8
# end
# Change the next two lines to your Evernote folder, and the folder where you would like to store your backups
watch_folder = File.expand_path("/Users/USERNAME/Library/Containers/com.evernote.Evernote/Data/Library/Application Support/com.evernote.Evernote/accounts/")
mark_folder = "~/Dropbox/Evernotes/"
# This Applescript grabs information from the current Evernote Doc
# Change line 26 to get specific notebooks (using "or notebook of item 1...")
result = %x{ osascript <<APPLESCRIPT
set list_Tags to {}
set names_Tags to ""
tell application "Evernote"
if selection is not {} then
set the_selection to selection
if notebook of item 1 of the_selection is (notebook named "Writing") or notebook of item 1 of the_selection is (notebook named "Book Project") then
set content to HTML content of item 1 of the_selection
set the_title to title of item 1 of the_selection
set list_Tags to tags of (item 1 of the_selection)
set count_Tags to count of list_Tags
repeat with list_Tag in list_Tags
set the_Name to name of list_Tag
set names_Tags to (names_Tags & the_Name as string)
if count_Tags is greater than 1 then
set names_Tags to (names_Tags & ", " as string)
set count_Tags to (count_Tags - 1)
end if
end repeat
return the_title & "#{DELIMITER}" & names_Tags & "#{DELIMITER}" & content
return "no"
end if
return ""
end if
end tell
if result == "no"
title, tag, note = result.split(DELIMITER, 3)
tag = tag.gsub(/\s/, "")
txtnote = %x{echo '#{note.gsub("'",'__APOSTROPHE__')}'|textutil -stdin -convert txt -stdout | /usr/local/bin/pandoc -f html -t markdown_strict --no-wrap}
title = title.strip
file = mark_folder+"#{title}"+".md"
watch_note =,'w+')
watch_note.puts txtnote.gsub(/\\_\\_APOSTROPHE\\_\\_/, "'").gsub(/\\/, "")
file = file.gsub(/\s/, "\\\s")
`tag -s #{tag} #{file}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment