Skip to content

Instantly share code, notes, and snippets.

Created April 6, 2013 18:48
Show Gist options
  • Save ttscoff/5327167 to your computer and use it in GitHub Desktop.
Save ttscoff/5327167 to your computer and use it in GitHub Desktop.
New version of EverWatch for integrating Marked with Evernote
#!/usr/bin/env ruby
# everwatch.rb by Brett Terpstra, 2011
# Updated for latest Evernote configuration (2013) and quick launch of - spetschu
# Watch Evernote for updates and put the current content of the editor into a preview file for
# <>
require 'shellwords'
trap("SIGINT") { exit }
watch_folder = File.expand_path("~/Library/Containers/com.evernote.Evernote/Data/Library/Application Support/Evernote/accounts/Evernote")
marked_note = File.expand_path("~/")
counter = 0
def get_html
%x{ osascript <<APPLESCRIPT
tell application "Evernote"
if selection is not {} then
set the_selection to selection
set the_html to HTML content of item 1 of the_selection
set the_html to ""
end if
return the_html
end tell
def write_note(note,target)
unless note == ""
txtnote = %x{echo #{Shellwords.escape(note)}|textutil -stdin -convert txt -stdout},'w+') {|f|
f.puts txtnote
unless File.exists?(marked_note),"w+") {|f|
f.puts "## Loading Evernote note\n\nThis file will update after you make a change and save."
`open -a ~/`
while true do # repeat infinitely
# recursive glob needed for current Evernote setup
files = Dir.glob( File.join( watch_folder, "**/*") )
# check for timestamp changes since the last loop
new_hash = files.collect {|f| File.exists?(f) ? [ f, File.stat(f).mtime.to_i ] : false }
hash ||= new_hash
diff_hash = new_hash - hash
if diff_hash.empty? # if there's no change
# if it's been less than 10 seconds, increment the counter
# otherwise, set it to zero and wait for new changes
counter = (counter < 10 && counter > 0) ? counter + 1 : 0
hash = new_hash
counter = 1
if counter > 0 # if the time is running
sleep 1
Copy link

foxjeff commented Apr 27, 2013

Hey Brett,


`open -a ~/`

is a great idea, but I had changed the marked_note variable above, so I changed the open like this:

`open -a "#{marked_note}"`

I hope this helps you or someone else.

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