Last active
October 12, 2018 02:52
-
-
Save craigeley/9e526e9f0681de4534cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/www.evernote.com/ACCOUNT_NUMBER/content/") | |
mark_folder = "~/Dropbox/Evernotes/" | |
DELIMITER = '%!%' | |
# 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 | |
else | |
return "no" | |
end if | |
else | |
return "" | |
end if | |
end tell | |
APPLESCRIPT}.chomp | |
if result == "no" | |
exit | |
else | |
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 = File.new(File.expand_path(file),'w+') | |
watch_note.puts txtnote.gsub(/\\_\\_APOSTROPHE\\_\\_/, "'").gsub(/\\/, "") | |
watch_note.close | |
file = file.gsub(/\s/, "\\\s") | |
`tag -s #{tag} #{file}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment