I use Evernote on a daily basis, but there’s no easy and quick way to create new notes and receive their shared URLs on iOS. While I tend to prefer plain text files, Evernote notes are quite useful when I need to share rich text (containing formatting and inline images) with someone else. Sharing via the official Evernote app takes too long, and I don’t like the UI of other Evernote clients.
Yesterday, Pythonista developer Ole Zorn posted an installer script for the Python Evernote SDK. By putting together all the necessary dependencies, he created an installer script that will create an “evernote-sdk” sub-folder in Pythonista 1.3; with that, you’ll be able to access the entire Evernote API to create and manage notes – all while taking advantage of the uniqe iOS-related features of Pythonista.
Inspired by Ole’s demoes and the snippets posted by Brett Kelly in the past weeks, I created a script that does exactly what I need: it lets me enter text to save it in an Evernote note that will be shared publicly. If triggered by an app like Drafts or Launch Center Pro, the script will take the text sent by those apps. If formatted in Markdown, the text will be converted to HTML before saving it to Evernote.
Install the Evernote SDK inside Pythonista using Ole’s installer.
To use the script, you’ll first need an Evernote account with an assigned developer token. You can generate a new token here; don’t ever share your private token with anyone else, as it’ll grant anyone access to your Evernote account.
To use the token in the script, rather than pasting it as a text string I recommend using the Pythonista keychain.
Obviously, I compiled the script for Pythonista 1.3, which was released last week.
What It Does
The script consider two possible scenarios: text sent from external apps like Drafts or Launch Center Pro, or text entered from Pythonista itself.
If you didn’t invoke the script from an external app, the script will ask you to enter a note title and body. Using your Evernote developer token, it will create a new note in your default notebook, share it, returning the public URL of the note. The script will display the link in the console as a tappable URL, and it’ll also place it in the iOS clipboard.
If the script, however, was triggered by another app, it will count the arguments passed in the URL scheme. If you like to write in Drafts and then launch the script, it’ll treat the first line as the note’s title, and the rest as the body. If you prefer Launch Center Pro, it will use the first keyboard prompt as title, the second as body.
In both cases, Markdown will be converted to HTML using markdown2 with support for footnotes and header IDs. On my iPad mini, a 1000-word, Markdown-formatted note takes around 15 seconds to be processed, saved, and shared in Evernote.
You can find the full script on GitHub.
This time, I tried to comment the script inline as much as possible. Lines 21–22 construct the first portion of the Evernote public URL using
googlechromes:// – the Google Chrome URL scheme for “https://” links. If you want, you can use
safari-https:// to open the link in Safari instead.
Lines 29–35 take care of understanding whether the note title and text should be entered in Pythonista or extracted from another app, whereas lines 41–42 convert the body of the note from Markdown to HTML.
The actual note is created and saved in lines 46–72 using Evernote’s own markup language called ENML; lines 73–87 share the note publicly using a note’s unique identifier and generating a “share key”; these two values will complete the final URL, which is printed as a tappable link in the console, and copied to the clipboard.
Below, a video of the script in action. I used Drafts to create a new note and share it through Evernote.
Once the script is done, you’ll be able to view the shared note in the browser or share the links with your friends, who will see the note you just created on evernote.com.
From Other Apps
Thanks to the Pythonista URL scheme, we can launch the script from other apps, passing along text directly in the URL scheme.
As I showed in the video above, you can launch the script from Drafts using this action (it assumes the script is called EvernoteTextShare):
Or, if you prefer Launch Center Pro, you can create an action like this and use the keyboard prompt to enter title and body:
Overall, the script is very flexible and requires minimal management after it has been set up for the first time. You can enable x-callback-url to be taken out of Pythonista automatically once the note is uploaded. You can remove the Markdown conversion, or even open another app like, say, a Twitter client to immediately tweet the link to the shared note.
If you have suggestions for improvements (for instance, I didn’t add any code to check for Evernote errors), ping me on Twitter.
- I just want to paste/enter some text and immediately receive the public Evernote URL of a shared note. ↩