Monday 10 January 2022

Using Apple Shortcuts to track my New Year’s Resolutions

You can listen to our latest podcast on New Year's Resolutions here

Introduction

Each year I make a couple of New Year’s Resolutions, including a reading and running goal. To stay on track, I know I can quickly calculate how many kilometres I should have run so far this year or how many pages I should have read.

Rather than work this out manually every day, I thought I would create an Apple shortcut to give me an update. I hadn’t made one before, so thought I would combine learning something new with helping keep to my goals, so here’s how I did it.

Figure 1 - My Goal Shortcuts

The following results are from my first day playing with Apple Shortcuts. Thank you for your patience with the poorly named variables and probable sloppy steps to achieve the end results. Feel free to comment where I can save time or add efficiency.

Reading Goal

My goal is to read 8000 pages in a year, so I need to read 8000/365 pages per day (~22 pages a day). Times this by the number of days passed this year and you have the daily target. Easy enough in January, bit harder as you move through the months.

The following is what I set up in the Shortcut:

  1. “Set a variable” as the Current Date called ‘Today’
  2.  “Get the time between” the last day of last year (31/12/2021) and the variable ‘Today’
  3. “Set a variable” called ‘NumOfDay’ to the result of “Get the time between”
  4. Do a “Calculation” of 8000 / 365
  5. “Set a variable” called ‘PagesPerDay’ to the result of the “Calculation” function
  6. Do a “Calculation” of ‘PagesPerDay’ times ‘NumOfDay’ i.e. on 8th January – 8 * 22 = 176
  7. “Set a variable” called ‘PagesSoFar’ to the result of the ‘PagesPerDay’ times ‘NumOfDay’ calculation
  8. Round the ‘PagesSoFar’ to One Place
  9. Speak the Rounded Number

Below are the images to make it a bit clearer. 


Figure 2 - How many pages should I have read shortcut

The title of the Shortcut was “How Much Should I Have Read” which is what you say to Siri to get the output. Like today 9th January responds with 198.

Running Goal

I can repeat the same steps for my running goal of 600km. Changing the variable names and the 8000 to 600. 


Figure 3 – How many kilometres should I have run shortcut

So, I know how many kilometres I should have run, but how can I track how many I have actually run using Apple Shortcuts? Well, there doesn’t seem to be an out of the box Strava, Nike+ or Fitbit shortcut to get run totals or add runs.

Tracking Runs

There is an extensive set of Apple Notes shortcuts, so I set up a Note called “Running” where I can add keep a tally of runs. From that note, I was able to create two additional shortcuts, “Add Run to Total” and “What Distance have I Run”.


Figure 4 - Running Note

Add Run to Total

To add new runs to the Note, the Notes “Append” shortcut was used with the dictated text to allow a number to be said. Start off by saying “Hey Siri, Add run to Total”, Siri asks for input, you say how many kilometres you did on your run and it will add it to the end of the note.

The following is what I set up in the Shortcut:

  1. Add “Dictate Text” function
  2. Use the “Get numbers from” function from the dictated text
  3. “Set a variable” called ‘RunNum’ to the Calculator Numbers
  4. Use the “FindNote” function looking for a note with “Running” in the name
  5. Use the “Append” function to add ‘Numbers’ to the returned note. 

Figure 5 - Add Run to Total Shortcut

What distance have I done?

As I’m adding the runs, there needs to be an easy way of totalling them and then asking Siri to tell me the total without me having to add it all up. This is fairly simple if we iterate over the runs in the Note and add them to a variable before getting Siri to speak the variable back to us. 

The following is what I set up in the Shortcut:

  1. Use the “FindNote” function looking for a note with “Running” in the name
  2. Split the returned Note by New Lines (one for each run)
  3. Use the “Calculate” function to instantiate a variable soon with 0 + 0
  4. “Set a variable” called ‘TotalRuns’ which is a result of the previous calculation
  5. Start a loop of each line of the note by using the “Repeat” function with each item in the split text
  6. Discount the title line “Running” using the “If” function with a check that the repeated item isn’t “Running”
  7. Inside the if add the current lines run amount ‘Repeat Item’ to the running total variable ‘TotalRuns’
  8. Use “Set a variable” to set the already created ‘TotalRuns’ to the calculated value
  9. End the IF
  10. End the Repeat
  11. Set some text using the “Text” variable to be “km this year”
  12. Use the “Speak” function to output the ‘TotalRuns’ variable
  13. Use the “Speak” function to output the ‘Text’

This will output the total run distance this year from the Running Note with “km this year” after i.e., 12 km this year 


Figure 6 - What Distance Have I Done shortcut

So, What Next?

I can add runs to the Note, I can get the total distance I have ran and the target number of kilometres for the number of days passed. Next might be to get how many kilometres over or under the target I am.  

Other shortcuts that might come in useful:

  • Automatically add items to my “AnyList” shopping list
  • Open the garage in case my hands are full
  • Add information to a spreadsheet

Let’s see how I get on!

No comments:

Post a Comment