Skip to content

Instantly share code, notes, and snippets.

@brandonb927
Forked from valpackett/LICENSE.md
Last active October 11, 2020 09:13
Show Gist options
  • Save brandonb927/5283527 to your computer and use it in GitHub Desktop.
Save brandonb927/5283527 to your computer and use it in GitHub Desktop.
Use Markdown in Evernote with Marked.app

Overview

Uses Evernote's Mac client and Marked (or similar Markdown-preview app) to allow you to create Markdown-style notes and preview them.

Requires

  • Evernote's Mac client
  • Marked (or similar Markdown-preview app)
  • Some Python and commandline knowledge

Setup

Step 1)

Setup Python so the script can be used. Using the awesome pip Python package manager, install 2 packages: html2text and MacFSEvents

$ [sudo] pip install html2text MacFSEvents

(Optional) Unless you are already familiar with Python, you may not have pip installed. Skip to the bottom for how to do this

Step 2)

Create the file EvernoteSelection.md in ~/Documents or wherever you want this file to sit, just remember to reference it in the script. It is essentially a cache file and contains only the information of your Evernote when you hit save.

Step 3)

Create the script file then paste the contents of the Python script into evernote_selection.py

$ [sudo] touch evernote_selection.py

Make the necessary edits to the Python script and save it somewhere. Make the script executeable and run it

$ [sudo] chmod 775 evernote_selection.py
$ [sudo] python evernote_selection.py

Step 4)

Save a note in Evernote with the content using Markdown syntax, then start Marked.app and open EvernoteSelection.md. You should now see the Markdown preview of your note!

Install pip Python package manager

To install pip the proper way, give the Python Guide a read through. For the lazy or inexperienced, install pip in one go: (Note: [sudo] is whether or not you need sudo to run commands.)

$ [sudo] easy_install pip
#!/usr/bin/env python
import os
import time
import codecs
from html2text import html2text
from fsevents import Observer, Stream
home = os.environ["HOME"]
now = lambda: time.mktime(time.localtime())
last = now()
def cb(*args):
global last
if now() - last > 1:
codecs.open(os.path.join(home, "Documents/Evernote Selection.md"), "w", "utf-8") \
.write(html2text(os.popen("""osascript -e \
'tell application \"Evernote\"
if selection is not {} then
set the_selection to selection
return HTML content of item 1 of the_selection
else
return \"\"
end if
end tell'""").read().decode("utf-8")))
last = now()
cb()
observer = Observer()
observer.schedule(Stream(cb, os.path.join(home, "Library/Containers/com.evernote.Evernote/Data")))
observer.start()
       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
               Version 2, December 2004

Copyright (C) 2011 Grigory V. [email protected]

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  1. You just DO WHAT THE FUCK YOU WANT TO.
@dredhorse
Copy link

Hi, I get the error message that there is no html2text modul even after running sudo pip install html2text a second time.

@vaz
Copy link

vaz commented May 13, 2015

You might have installed python with homebrew? And that python lives in /usr/local/bin/python.

You might have to change that, or (assuming the PATH is correct, which might not be the case if this is a shell script loaded on boot by LaunchAgent) maybe /usr/bin/env python ... but probably the direct path is what you need.

Do which pip and if it was in .e.g. /usr/local/bin/pip then you know to change it to /usr/local/bin/python.

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