Jump to content

Reverse ordered blocks of text with code

Recommended Posts

I keep a running list of quick-jots in Evernote. They are compiled by prepending text, separated by "––", to an already existing note (vs appending). Appending created too many spacing errors for my liking.


I'm looking for a way to select all text (and inserted images) and reverse their order; in HTML preferably so that already existing font-styles are preserved.


Example note content in Evernote:


This item is noted here.


Another item is noted here.

- This is a bulleted item under previous note

- This is another bullet


Yet another item is here...


...and so on


Any ideas or existing workflows?

Link to comment

Here's how I'd do it:


create a Hotkey with Selection in MacOS as argument


pipe that to a bash script object containing the following script:



echo "$query" | tail -r

pipe that out to a Copy to Clipboard object, optionally setting it to paste to the frontmost app



....but this isn't going to capture HTML/rich styling or images.  If Evernote lets you view the HTML source, you could select the source and run the same script - that would handle your images, then you'd need to run some other code to clean the HTML tags so the open and closing tags aren't flipped (there's the trick with HTML -- you're reversing the content, but the order of the tags actually needs to stay the same & not be reversed).

Edited by dfay
Link to comment

@dfay I'm thinking @jonteamere wants the order of the notes reverse, not the lines.


If that is the case, it would almost certainly be easier to fix whatever issue is causing your spacing errors with append.


Fix append: strip extra leading/trailing lines before appending. There's an action in Alfred for it, and it's not even a one-liner in any programming language worthy of the name.


Reverse prepended notes: Extract HTML from Evernote. Parse HTML. Identify which tags belong to which notes. Reverse the order of those collections of tags. Replace the note content in Evernote with your updated HTML.



Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...