Let Siri read you an ebook

Hey folks!

I’ve been loving Scriptable lately after I discovered a few impactful use cases for my own life:

  • Using Scriptable’s notification support has opened up a super convenient way to run automations at scheduled times with minimal taps required (one example: a notification as a reminder and quick way to send a message that I’m heading home from work at my usual time)

  • Automating the reading of large pieces of text (such as an ebook)

Please check out this script that will read a book to you:

A few quirks:

  • I’m using x-callback-url integration to offload both dictation and speaking to Shortcuts. Shortcuts allows for hands-free dictation as well as pitch/speed control for speech.
  • After selecting an action in the webview, the user has to dismiss it with the modal view controller’s Done button. I wish there were a way to dismiss the modal from within the webview’s JavaScript
2 Likes

Thanks for sharing :blush:

Just a side not but when you’re hosting scripts meant to be imported into Scriptable on GitHub, you may want to share the raw JavaScript file since GitHub serves the raw files in a way that prevents Safari from detecting the content type. Scriptable provides an action for sharing as a raw JavaScript in the share sheet from within the app.

1 Like

I’ve only taken a brief look at your script som I may be overlooking something but you could consider one of two to address the issue:

  • Use a UITable for picking an action. The UITable have an API for dismissal.
  • Call Scriptables URL scheme from your WebView, e.g. scriptable://run?scriptName=Read&20Ebook&action=foo. That will run your script again but with the action=foo parameter. You can check for the parameter using URLScheme.allParameters() and perform the appropriate action.
1 Like

Thanks for the awesome app! And thank you for reading!

I updated the link above to point to the .js file instead!

I found that I couldn’t get a UITable to look good for the amount of text I want to show (I think there’s no way to set the font size? And I see weird text truncation happen). I’ll try reentering the script with a URL instead like you suggest!

I tried opening a Scriptable URL from within my web view’s html. Sadly, it doesn’t appear to have an effect — tapping a button or link didn’t reopen the script; the web view just stays up.

I tried the same HTML in Safari and the link does work from there so I think this may be a web view issue?

One thing I just thought to try next is to hook into the shouldAllowRequest handler to see if I can open the Scriptable URL from there.

Here’s the good news:
This worked to re-enter the Scriptable app and run my script:

webView.shouldAllowRequest = (request) => {
console.log("ShouldAllowRequest: " + request.url)

if (request.url.startsWith("scriptable://")) {
  Safari.open(request.url)
}

return true

}

Here’s the bad news:

After opening Scriptable via URL, the URLScheme parameters will always be set until I kill the app. If I run the script with the play button, it’ll think I’m re-entering via URL. I could store some state on disk to indicate that I already handled this URL but that gets super messy :frowning: