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 evernote_selection.py into it

$ [sudo] touch evernote_selection.py

Step 4)

Create a file called com.user.evernote_markdown.plist in ~/Library/LaunchAgents

Step 5)

Create the script evernote_selection.sh that will run on boot anywhere on your computer, but remember to reference it in com.user.evernote_markdown.plist

Step 6)

Add the executable bit to the file with

$ [sudo] chmod +x /path/to/evernote_selection.sh`

Step 7)

Logout and login again

Step 8)

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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.evernote_markdown</string>
<key>Program</key>
<string>/path/to/evernote_selection.sh</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#!/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()
"""
Change these variables if needed
-file : You must create and name this file, place the file path here
-libpath : If it exists, use ~/Library/Containers/com.evernote.Evernote/Data
otherwise, use ~/Library/Application Support/Evernote/data
"""
file = "Documents/EvernoteSelection.md"
libpath = "Library/Containers/com.evernote.Evernote/Data"
filepath = os.path.join(home, file)
datapath = os.path.join(home, libpath)
def cb(*args):
global last
if now() - last > 1:
codecs.open(filepath, "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, datapath))
observer.start()
#!/bin/sh
/usr/bin/python /path/to/evernote_selection.py -d
       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
               Version 2, December 2004

Copyright (C) 2012 Brandon B. [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.
@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