March 22, 2020

Turning webpages into EPUBs on iOS using Scriptable, Shortcuts, and EpubPress

When I find a really long article on the web that I can’t get through in one sitting, I like to convert it to an EPUB and read it in the Books app on iOS/Mac. It saves my position across devices, and I can highlight and add notes.

On the Mac I use EpubPress, a great service that extracts article content from webpages into a single EPUB, but I couldn’t do this on iOS.

Using a combination of Scriptable and iOS Shortcuts, we can run a modified version of EpubPress’s JS client to bring that functionality onto a mobile device.

This essay has over 20,000 words so we want to export it to the Books appThis essay has over 20,000 words so we want to export it to the Books app

Step 1: Set up Scriptable

Scriptable is an amazing app, firstly because it allows you to run JavaScript on iOS with deep integration into system APIs, but it’s also just a damn nice iOS app to use. Simon Støvring has nailed the UI and functionality with this app.

So once you have that installed, go to Settings > File Bookmarks to add a Folder Bookmark called Shortcuts”, which points to your Shortcuts directory in iCloud Drive:

Setting a bookmark on the Shortcuts directory in iCloud DriveSetting a bookmark on the Shortcuts directory in iCloud Drive

Then create a new script called Download EPUB:

Download EPUB script in ScriptableDownload EPUB script in Scriptable

And paste this code:

Step 2: Set up iOS Shortcuts

The shortcut on the left calls the shortcut on the rightThe shortcut on the left calls the shortcut on the right

Add these two shortcuts to your iOS Shortcuts app:

  1. Add to Books as EPUB: this one is the main driver, it’s what you’ll select in the Share Sheet from the webpage you want to convert.
  2. Add Downloaded EPUB to Books: this shortcut exists as a workaround to the issue described below. It gets called right at the end of the Scriptable script, and it adds the downloaded EPUB to your Books app.

What if I don’t want to add the EPUB to Books?

If you just want to download EPUBs to iCloud Drive but don’t want them added to the Books app, you can just comment out or remove this line at the very end of the Scriptable script:

shortcutsCallbackUrl.open();

You also won’t need the second iOS Shortcut called Add Downloaded EPUB to Books”


iOS Shortcuts JavaScript


Previous post
How to create a slide-over card using SwiftUI (like in Maps or Stocks)
Next post
MKLocalSearchCompleter results in SwiftUI using Combine