<sup>Date: September 9, 2024</sup> I keep a budget spreadsheet in Google Sheets to track account balances and money in/out. It doesn’t have anything fancy like an API connection to automatically pull data from my accounts, but hey, it’s free. To populate transactions in the spreadsheet, I use Google Forms. There’s an important feature that will allow us to automate spreadsheet data entry: the ability to get a pre-filled link for a Google Form. This pre-filled link will have the following format: ``` https://docs.google.com/forms/d/e/FORM_ID/viewform?usp=pp_url&entry.XXXXXX=5.69&entry.XXXXXX=Outflow&entry.XXXXXX=Walmart&entry.XXXXXX=Groceries&entry.XXXXXX=Paypal+Card ``` If we take note of these `entry.XXXXXX` values, we can pass them as URL parameters in an HTTP GET request. Then, if we just add parameter `&submit=Submit` to the end of the URL, we can use this effectively as a REST endpoint for our Google Form. iOS Shortcuts has an action called “Get contents of” action, which makes an HTTP GET request. For a long time I entered data manually, prompting for data like dollar amounts and budget categories using Shortcuts’ input and menu actions. However, I’ve configured most of my payment methods and bank apps to send push notifications to my iPhone when a purchase is made. Using Shortcuts' built-in Optical Character Recognition (OCR) and Regular Expressions, we can automate transaction entry to the Google Form. The overarching Shortcut will look like this (with more steps for each bank app that I truncated for brevity): ![[Main Shortcut.jpg]] I have a “Matcher” shortcut for each app so that I can parse and manipulate different notification formats from different banks. Here’s an example of my PayPal matcher. ![[PayPal Example.jpg]] Using a regular expression with capture groups, we can extract the name of the payee and the amount of the transaction. I run a shortcut that prompts for which budget category the transaction should be entered under, like Groceries or Utilities. Then, I wrap that data into a dictionary variable that I can pass to the final step which makes the HTTP GET request using the data from the dictionary. > [!note] A note on PayPal notifications: > With PayPal, we don’t always get the name of the payee in the notification. In this case, the first capture group will return “PayPal” and we can prompt the user to input a payee. ![[Dictionary Object.jpg]] In my experience, Shortcuts’ OCR mostly be trusted, but I’ll still present input prompts with the parsed data as default values in case anything needs to be changed. If it all looks right, it’s just a few taps to get the transaction submitted to the spreadsheet. Here’s a GIF to show how the overall flow works. ![[Shortcut Flow.gif]] Ultimately, I now open my spreadsheet about once a week just to reconcile balances. Entering items through a shortcut with OCR takes just a few seconds, instead of having to manually enter the data into input prompts myself. In the future, I might develop a regex pattern to parse lists of transactions from the account overview in any given bank app so that I can enter if I miss or accidentally dismiss a notification. Also, troubleshooting can be kind of clunky - I usually just add an action to display the OCR’ed text and throw it into [Regexr](https://regexr.com/) to see where I went wrong. Eventually, I want to add a debug file in my iCloud Drive to log the OCR’ed text and whether there were any matches so that I can review and test my regex at a later time. > [!warning] A note on sharing > Unfortunately due to the way I’ve set up my spreadsheet and these shortcuts, it wouldn’t be practical for me to share them. However, I hope this post gives a bit of insight on how a similar process could be put together using Shortcuts' OCR.