Updating Nanowrimo Wordcount with Siri Shortcuts

I share a workflow for Siri Shortcuts that lets you update your Nanowrimo word count from your iPhone or iPad


Updating Nanowrimo Wordcount with Siri Shortcuts

I’m writing this on day three of Nanowrimo 2018 and I’ve got to make up some ground! Since word counts are on my mind, I wanted to share a tutorial on how you can update your Nanowrimo word count using Siri Shortcuts (formerly Workflow.app) on your iPhone or iPad.

I originally created this workflow back in 20171, but it was too late in November to bother sharing. My need was simple. I was writing a lot on my iPad, often without wifi, and I needed a simple and quick means to update my word count without signing into my Nanowrimo account and fiddling with the mobile version of the Nano website on my iPhone 5S.

Here’s a demonstration of how it works.



If you’re time challenged, you can grab a copy of my workflow from iCloud and modify it to suit your needs. You’ll need to be on the latest iOS and have Siri Shortcuts installed. You’ll also need your Nanowrimo API key — if you don’t know what that means, or where to get it, glance through my detailed instructions below.

How to build your own from scratch

Before I begin, I should note that I build all my workflows on my iPad, rather than my iPhone, to take advantage of the larger screen and my Brydge Keyboard. Once created there, the workflows are synched to my iPhone via iCloud. For the sake of this tutorial, all screenshots below were taken from my iPad.

Nanowrimo API

Before you can build and test your workflow, you need your Nanowrimo API2 key. This is a secret string of characters used to access your Nanowrimo account remotely.

Doing so is easy, simply visit this page, while you are logged into your account. Your key will be displayed on the page. Note the warning to keep your key hidden — if someone acquires your key, they’ll be able to compromise your account, so keep it safe!

The page also gives you detailed instructions on how to use the API to change your word count. Don’t worry if it looks complex; I’ve done the hard work for you!

Building the workflow in Siri Shortcuts

Siri Shortcuts (formerly Workflow) is an amazing utility that allows you to automate complex tasks on your iOS devices without a lick of programming language. It does so by allowing you to chain actions together using visual blocks. Actions perform discreet functions against data — be it text, documents of various format, photos or even videos. It can even pass data between apps on your device in a way that doesn’t contravene Apple’s strict sandboxing rules. Most importantly for our purposes, Shortcuts can interact with web services.



To build the workflow:

  1. Add an ‘Ask for Input’ block and set the Input Type as Number.
  2. Save this as a variable called WordCount using a ‘Set Variable’ block.
  3. Next, add a ‘Nothing’ block. This ensures our new variable isn’t passed on to the next action accidentally.
  4. Add a ‘Text’ block and insert your Nanowrimo user account name as the value. Mine is ChrisRosser and note it’s case sensitive.
  5. Save this as a variable called UserName using another ‘Set Variable’ block.
  6. Next, create another ‘Text’ block and insert your Nanowrimo API key as the value. Yours is unique to you and is available here.
  7. Save your Key as a variable called SecretKEY using another ‘Set Variable’ block.
  8. Add a ‘Nothing’ block as before.
  9. Now things get interesting. Create a new ’Text’ block and add your variables on the same line, with no spaced separating them (see the screenshot below).
  10. We need to convert the variables in a Hash using the SHA1 algorithm. Simply add a ‘Generate Hash’ block and select SHA1 as the Type.
  11. Then save this to a new variable called Hash using another ‘Set Variable’ block.
  12. Add another nothing block to ensure we don’t pass this variable on by mistake.
  13. Now it’s time to send this off to the Nanowrimo API! Add a ‘URL’ block using https://nanowrimo.org/api/wordcount as the value.
  14. To talk to the API, we’ll need a ‘Get Contents of URL block. Expand the Advanced arrow and configure as following:
    • Method: PUT
    • Request Body: JSON
    • Then add three fields:
      • hash: Hash variable
      • name: UserName variable
      • wordcount: WordCount variable
        If all’s gone well, our word count has been updated, however we can read the response from Nanowrimo and create a notification.
  15. Grab the response by adding a ‘Get Text from Input’ block. The response is a little messy so we’ll have to process it.
  16. Add a ‘Replace Text’ block with the following parameters:
    • Find Text: =>
    • Replace with: : (a colon character)
    • Case Sensitive: Enabled
    • Regular Expression: Disabled
  17. Next we need to convert the output of the previous block into a data format Shortcuts can work with. To do so add a ‘Get Dictionary from Input’ block.
  18. Save this dictionary to a variable called Response using another ‘Set Variable’ block.
  19. Next we’ll extract part of the data block containing our novel’s information by adding a ‘Get Dictionary Value’ block with the following parameters:
    • Get: Value
    • Key: novel
  20. The novel element still contains some extraneous stuff I don’t want, so we’ll remove it with another ‘Replace Text’ block using the following parameters:
    • Find text: November \d{4} -
    • Replace with: LEAVE THIS FIELD BLANK
    • Case Sensitive: Enabled
    • Regular Expression: Enabled
  21. Next we’ll save this modified response as a variable Novel.
  22. Finally, we’ll create a notification using the ‘Show Notification’ block using the following parameters:
    • Title: Word Count Updated
    • Message: Novel word count updated to WordCount (Note that Novel and WordCount are the variables we created earlier.
    • Play Sound: Enable

Concluding thoughts

Siri Shortcuts has almost endless possibilities, allowing you to automat just about anything you can do with files, apps and even web services.

In this tutorial I showered you how I use it to update my word count, something I do literally hundreds of times during the month of February. Feel free to download and adapt my workflow to suit your needs.

I hope you find this useful — not just for Nanowrimo. If this was the first time you’ve seen Shortcuts in action, I hope I inspired you to automate all the boring crap in your life so you can spend more time doing what’s important to you!

Let me know how you go. I’d love to see the workflows you’ve created!


  1. And it replaced an older Python script I created for Nanowrimo 2016! 

  2. Application Programming Interface 

Comments

There are no comments yet. Click the button below to start the conversation!

Article Details

Published in Tutorials

Permalink

5 min read | 1078 words


Share on:

Connect on social media
Support my writing

Liked this article and want to support my site?

If you're an Amazon customer, please consider using one my affiliate links for the USA or UK Amazon stores.

Prefer another way to support my site?