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.

Revisions

  1. Brandon Brown revised this gist May 1, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion com.user.evernote_markdown.plist
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    <key>Label</key>
    <string>com.user.evernote_markdown</string>
    <key>Program</key>
    <string>/usr/bin/python /path/to/evernote_selection.py -d</string>
    <string>/path/to/evernote_selection.sh</string>
    <key>RunAtLoad</key>
    <true/>
    </dict>
  2. Brandon Brown revised this gist Apr 4, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -28,10 +28,10 @@ Create the script file then paste the contents of [evernote_selection.py](https:
    $ [sudo] touch evernote_selection.py

    #### Step 4) ####
    Create a file called `com.user.evernote_markdown.plist` in `~/Library/LaunchAgents` and add the code from [here](https://gist.github.com/brandonb927/5283527#file-com-user-evernote_markdown-plist)
    Create a file called [com.user.evernote_markdown.plist](https://gist.github.com/brandonb927/5283527#file-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 toreference it in `com.user.evernote_markdown.plist`. Code is [here](https://gist.github.com/brandonb927/5283527#file-evernote_selection-sh)
    Create the script [evernote_selection.sh](https://gist.github.com/brandonb927/5283527#file-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
  3. Brandon Brown revised this gist Apr 4, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ Create the file `EvernoteSelection.md` in ~/Documents or wherever you want this
    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
    Create the script file then paste the contents of [evernote_selection.py](https://gist.github.com/brandonb927/5283527#file-evernote_selection-py) into it

    $ [sudo] touch evernote_selection.py

  4. Brandon Brown revised this gist Apr 4, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ Create the script file then paste the contents of the Python script into evernot
    Create a file called `com.user.evernote_markdown.plist` in `~/Library/LaunchAgents` and add the code from [here](https://gist.github.com/brandonb927/5283527#file-com-user-evernote_markdown-plist)

    #### Step 5) ####
    Create the script `evernote_selection.sh` that will run on boot anywhere on your computer but remember reference it in `com.user.evernote_markdown.plist`. Code is [here](https://gist.github.com/brandonb927/5283527#file-evernote_selection-sh)
    Create the script `evernote_selection.sh` that will run on boot anywhere on your computer, but remember toreference it in `com.user.evernote_markdown.plist`. Code is [here](https://gist.github.com/brandonb927/5283527#file-evernote_selection-sh)

    #### Step 6) ####
    Add the executable bit to the file with
  5. Brandon Brown revised this gist Apr 4, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ Create the script file then paste the contents of the Python script into evernot
    Create a file called `com.user.evernote_markdown.plist` in `~/Library/LaunchAgents` and add the code from [here](https://gist.github.com/brandonb927/5283527#file-com-user-evernote_markdown-plist)

    #### Step 5) ####
    Create the script that will run on boot, anywhere on your computer but remember reference it in `com.user.evernote_markdown.plist`. Code is [here](https://gist.github.com/brandonb927/5283527#file-evernote_selection-sh)
    Create the script `evernote_selection.sh` that will run on boot anywhere on your computer but remember reference it in `com.user.evernote_markdown.plist`. Code is [here](https://gist.github.com/brandonb927/5283527#file-evernote_selection-sh)

    #### Step 6) ####
    Add the executable bit to the file with
  6. Brandon Brown revised this gist Apr 4, 2013. 1 changed file with 16 additions and 18 deletions.
    34 changes: 16 additions & 18 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -14,41 +14,39 @@ Uses Evernote's Mac client and [Marked](http://markedapp.com/) (or similar Markd
    #### Step 1) ####
    Setup Python so the script can be used. Using the awesome `pip` Python package manager, install 2 packages: html2text and MacFSEvents

    ```shell
    $ [sudo] pip install html2text 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

    ```shell
    $ [sudo] touch evernote_selection.py
    ```
    $ [sudo] touch evernote_selection.py

    #### Step 4) ####
    Create a file called `com.user.evernote_markdown.plist` in `~/Library/LaunchAgents` and add the code from [here](https://gist.github.com/brandonb927/5283527#file-com-user-evernote_markdown-plist)

    Make the necessary edits to the Python script and save it somewhere. Make the script executeable and run it
    #### Step 5) ####
    Create the script that will run on boot, anywhere on your computer but remember reference it in `com.user.evernote_markdown.plist`. Code is [here](https://gist.github.com/brandonb927/5283527#file-evernote_selection-sh)

    ```shell
    $ [sudo] chmod 775 evernote_selection.py
    $ [sudo] python evernote_selection.py
    ```
    #### Step 6) ####
    Add the executable bit to the file with

    #### 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!
    $ [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](https://python-guide.readthedocs.org/en/latest/starting/install/osx/) 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.)

    ```shell
    $ [sudo] easy_install pip
    ```
    $ [sudo] easy_install pip
  7. Brandon Brown revised this gist Apr 4, 2013. 2 changed files with 15 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions com.user.evernote_markdown.plist
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?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>/usr/bin/python /path/to/evernote_selection.py -d</string>
    <key>RunAtLoad</key>
    <true/>
    </dict>
    </plist>
    3 changes: 3 additions & 0 deletions evernote_selection.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/sh

    /usr/bin/python /path/to/evernote_selection.py -d
  8. Brandon Brown revised this gist Apr 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion evernote_selection.py
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@
    file = "Documents/EvernoteSelection.md"
    libpath = "Library/Containers/com.evernote.Evernote/Data"

    filepath = os.path.join(home, path)
    filepath = os.path.join(home, file)
    datapath = os.path.join(home, libpath)

    def cb(*args):
  9. Brandon Brown revised this gist Apr 1, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion LICENSE.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004

    Copyright (C) 2011 Grigory V. <[email protected]>
    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
  10. Brandon Brown revised this gist Apr 1, 2013. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions evernote_selection.py
    Original file line number Diff line number Diff line change
    @@ -9,11 +9,23 @@
    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, path)
    datapath = os.path.join(home, libpath)

    def cb(*args):
    global last
    if now() - last > 1:
    codecs.open(os.path.join(home, "Documents/Evernote Selection.md"), "w", "utf-8") \
    codecs.open(filepath, "w", "utf-8") \
    .write(html2text(os.popen("""osascript -e \
    'tell application \"Evernote\"
    if selection is not {} then
    @@ -27,5 +39,5 @@ def cb(*args):

    cb()
    observer = Observer()
    observer.schedule(Stream(cb, os.path.join(home, "Library/Containers/com.evernote.Evernote/Data")))
    observer.schedule(Stream(cb, datapath))
    observer.start()
  11. Brandon Brown revised this gist Apr 1, 2013. 1 changed file with 47 additions and 4 deletions.
    51 changes: 47 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,54 @@
    Evernote's Mac client + [Marked](http://markedapp.com/) or similar: basically just setting ~/Documents/Evernote Selection.md to the content text of current note converted from HTML to Markdown.
    ## Overview ##
    Uses Evernote's Mac client and [Marked](http://markedapp.com/) (or similar Markdown-preview app) to allow you to create Markdown-style notes and preview them.

    First,

    ## Requires ##

    - Evernote's Mac client
    - [Marked](http://markedapp.com/) (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

    ```shell
    $ [sudo] pip install html2text MacFSEvents
    ```

    Then launch it and enjoy.
    (**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

    ```shell
    $ [sudo] touch evernote_selection.py
    ```

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

    ```shell
    $ [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!


    P.S. guess what, ⌘S works in Evernote.
    ## Install pip Python package manager ##
    To install `pip` the proper way, give the [Python Guide](https://python-guide.readthedocs.org/en/latest/starting/install/osx/) 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.)

    ```shell
    $ [sudo] easy_install pip
    ```
  12. Brandon Brown revised this gist Apr 1, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions evernote_selection.py
    Original file line number Diff line number Diff line change
    @@ -27,5 +27,5 @@ def cb(*args):

    cb()
    observer = Observer()
    observer.schedule(Stream(cb, os.path.join(home, "Library/Application Support/Evernote/data")))
    observer.start()
    observer.schedule(Stream(cb, os.path.join(home, "Library/Containers/com.evernote.Evernote/Data")))
    observer.start()
  13. Grigory V. revised this gist Nov 10, 2011. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,8 @@ First,

    ```shell
    $ [sudo] pip install html2text MacFSEvents
    ```
    ```

    Then launch it and enjoy.

    P.S. guess what, ⌘S works in Evernote.
  14. Grigory V. created this gist Nov 10, 2011.
    13 changes: 13 additions & 0 deletions LICENSE.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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

    0. You just DO WHAT THE FUCK YOU WANT TO.
    7 changes: 7 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Evernote's Mac client + [Marked](http://markedapp.com/) or similar: basically just setting ~/Documents/Evernote Selection.md to the content text of current note converted from HTML to Markdown.

    First,

    ```shell
    $ [sudo] pip install html2text MacFSEvents
    ```
    31 changes: 31 additions & 0 deletions evernote_selection.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/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/Application Support/Evernote/data")))
    observer.start()