Jump to content
richardsugg

windows (Archived) How to use Evernote as a TextExpander replacement?

Recommended Posts

I use EN on Mac and Windows, but for Windows especially, I would like to be able to quickly find and retrieve code snippets in a way similar to TextExpander on Mac or Breevy on Windows.

I could use AutoHotkey to capture keystroke triggers, but how would I extract the contents of a single note? I suppose I could do something like

1) Autohotkey captures the keystroke trigger and fires off enscript:

2) Find and export the note:

enscript exportNote /q "querystring" > %TEMP%\tmp.enex

3) Use Perl to find the contents (oh please let it be plain text)

perl_script.pl %TEMP%\tmp.enex

4) Autohotkey copies the plain text content of the enex to the clipboard and pastes it into the document where the keyboard trigger was typed

I currently have this working without Evernote. All the snippets are in text files, but that means I'm not using EN, which I would rather do. Is there a better approach than what I've outlined above?

Share this post


Link to post

Some sadness to report... When I look at the contents of the enex via Perl, here's what I see:

<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>

<!DOCTYPE en-note SYSTEM \"http://xml.evernote....ub/enml2.dtd\">

<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\">

require(["dojo/request"], function(request){ request.get("", { handleAs: "json"

<div>\x{a0} \x{a0} }).then(function(response){</div>

<div>\x{a0} \x{a0} \x{a0} \x{a0} console.log("response:", response);</div>

<div>\x{a0} \x{a0} }, function(err){</div>

<div>\x{a0} \x{a0} \x{a0} \x{a0} console.log("error:", err);</div>

<div>\x{a0} \x{a0} });</div>

<div>});</div>

<div><br/></div>

<div><br/></div>

<div><br/></div>

</en-note>

Is there any other way to get the text out? I made sure I copied the snippet from a text file into EN to be sure I wasn't inadvertently copying HTML.

  • Like 1

Share this post


Link to post

All notes in Evernote have an HTML (-ish) wrapper -- it's just text; you can look at it in a text editor. In particular, text with tabs is indented using divs as far as I recall. If you're going to process ENEX files, you are going to need to learn how to interpret the ENML format. See http://dev.evernote.com/start/core/enml.php.

Share this post


Link to post

Right @jefito but it's missing the CDATA and the quotes are backslash-escaped and I've never seen the string \x{a0}  in any data. And as @richardsugg mentioned Perl I wonder if it's got mangled along the way.

 

I agree I can see the text and it actually makes sense to me as some dojo javascript. :-)

Share this post


Link to post

Yeah, I can't vouch for the fidelity of the Perl translation, obviously.

Share this post


Link to post

I was hoping to get out the easy way, but I guess that won't be the case. I'll retool this weekend sometime and post an update. Thank you for the feedback!

Share this post


Link to post

Wow, that would great. I exported the note and looked again at it. It does appear that Perl was adding some wonkiness to it, as the strange chars aren't actually in the note.

 

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export.dtd"><en-export export-date="20130215T141040Z" application="Evernote/Windows" version="4.x"><note><title>dojo/request</title><content><![CDATA[<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>require(["dojo/request"], function(request){ request.get("%filltext:name=URL%", { handleAs: "json"</div><div>    }).then(function(response){</div><div>        console.log("response:", response);</div><div>    }, function(err){</div><div>        console.log("error:", err);</div><div>    });</div><div>});</div><div><br/></div></en-note>]]></content><created>20130215T141018Z</created><updated>20130215T141022Z</updated><tag>snippet</tag></note></en-export>

Share this post


Link to post

Take everything after the en-note tag and before the matching end tag and paste it into a flat file. Then open it in your browser. In my case (using Firefox) it was plainly visible, properly indented, javascript with all the   entity references resolved.

 

Might "get you home " this time. Above procedure might form the basis of something more robust - if someone had the spare time to write the code.

 

Another alternative is to see what geeknote does to it. You might lose the indentation, though.

 

And sorry I don't have the spare time to write the code. :-(

Share this post


Link to post

There are some % signs in it I don't understand:

 

require(["dojo/request"], function(request){ request.get("%filltext:name=URL%", { handleAs: "json"    }).then(function(response){        console.log("response:", response);    }, function(err){        console.log("error:", err);    });});

Share this post


Link to post

Ok - here's my first pass. If anyone tries this out, I'd love to hear from you. If there are corrections to be made, I'll be glad to make them. From the README.mmd:

 

 

# Don't blame me
Use at your own risk. If something goes wrong, don't blame me. You assume
full responsibility for whatever you run wherever you run it. If
something breaks as a result of this work, I will not accept any
responsibility.
 
# What It Is #
TextExpander (and it's Windows equivalent, Breevy) let you save snippets of text and assign hotkeys to them for quick retrieval. It's really handy for storing code snippets, but I'd really rather use Evernote for storing the code. AutoHotkey handles the hotkeys. If for some reason you aren't using Evernote, this also allows you to store snippets in text files. But why don't you want to use Evernote? :)
 
# Requirements
* If using Evernote, enscript.exe must be in your PATH
* If using Evernote, [Perl](http://www.activestate.com/activeperl/downloads), and Perl must be in your PATH
* If using Evernote, Perl module XML::Simple. Installation is very simple from a command prompt: 
 
    perl -MCPAN -e "install XML::Simple"
    
* If using Evernote, files with .pl extension must be executable. You can
test this by double clicking on parseTe.pl. If notepad opens, you're good
to go. If the file opens and you see code, you need to right-click, choose
"open with", and browse to perl.exe.
* Because this uses enscript.exe for getting notes out of Evernote, this is a Windows-only implementation. AutoHotkey could be swapped out for a number of other utilities on Mac, but it would take more work for me to replace enscript.exe.
 
# Warning #
If you use the Evernote method of storing and retrieving snippets, you
should be aware that I am running a system command:
 
    enscript exportNotes /q "tag:snippet intitle:USER_INPUT" /f tmpfile
 
USER_INPUT is stripped of the following characters: & ' " > <
So long as you don't try putting those characters in the title of a snippet,
you are fine.
 
# Installation
1. Place the scripts in My Documents\TextReplacements
2. Create a directory My Documents\TextReplacements\snippets
3. Launch TextReplacements.ahk or put
 
    #Include path/to/TextReplacements.ahk
 
in your autohotkey startup script.
 
# Usage
There are three ways of storing snippets. For each of these snippets, the
trigger is typing ,,em. The trigger for each snippet must be unique.
 
1. The first way is to put the snippet directly in TextReplacements.ahk.
This is good for short and simple abbreviations. 
 
    ;; personal email
    ::,,em::my.email@gmail.com
 
Notice that there is a comment above the abbreviations, and the comment
is prefixed with two semicolons. More on that later. If you have a longer
snippet or one that has special characters like backticks, braces, etc.,
you'll want to use one of the next two methods.
 
2. The second way is to have your snippets in files under the snippets
directory. For instance, if you have a file in the snippets directory
named "my_email.txt" that contains your email address, you would define
your way is the create a plain text note in Evernote, tag it as "snippet",
and give it a unique title. Define your abbreviation like
 
    ;; personal email
    ::,,em::
    ReadAndCopy("my_email.txt");
    return
 
This will read in the contents of my_email.txt and replace ,,em with the
contents.
 
3. The last way is to look in Evernote. The note should be plain text and
have a tag of "snippet". Give the note a unique name, such as "my email" 
(without the quotes). Define the abbreviation like
 
    ;; personal email
    ::,,em::
    ReadFromEvernote("my email");
    return
 
This will call the script en2te.pl script to dump the note to a text file.
The text file is then dumped wherever you are typing.
 
# Other
If you defined your snippets with the ;; comment above it, then the script
parseTe.pl will summarize your shortcuts and open a text file for you to
see them.
 

TextReplacements.zip

  • Like 1

Share this post


Link to post

Update - so what I have posted technically works, but I've already found several things that need to change. For one, I forgot I was using HOME as an environment variable. That is not a standard Windows env var, so you'd either have to change it to USERPROFILE in TextReplacements.ahk or create the env var HOME equal to your home directory.

 

However, I've run into another issue with enscript. I can't seem to pass the parameters correctly. For instance, I want to find notes that have a tag of snippet and a title of "dojo console". In EN, I can search with this:

 

 

tag:snippet intitle:"dojo console" 

With enscript, I've tried the following:

 

 

 

enscript showNotes /q "tag:snippet intitle:'dojo console'"enscript showNotes /q "tag:snippet intitle:"dojo console""enscript showNotes /q "tag:snippet intitle:dojo%20console"enscript showNotes /q 'tag:snippet intitle:"dojo console"' 

 

 

Nothing I've tried works. Any ideas? The first example above is the closest, but it doesn't actually work. It seems to ignore the single quotes and return notes with "dojo" in the title and "console" anywhere in the note. Instead of getting a single note back, I get several.

Share this post


Link to post

I've updated this project (a lot!) and put it on github. It also works on Mac, however, you'll have to find something like Apptivate or Keyboard Maestro to handle the hotkeys, since AutoHotkey does this for free on Windows. If you'd like to try this out, grab the project and read the readme:

 

https://github.com/richardsugg/TextRep

 

If you do try it out, please let me know what your experience is. I'd like for this to be as robust as possible, which can be tricky since I'm stringing things together. It has, though, worked pretty well for me.

Share this post


Link to post
Guest
This topic is now closed to further replies.

×
×
  • Create New...