Tot shopping redux

A couple of days after the post about my Tot shopping list was published, I got this request on Mastodon from roguewolf:

I wonder if it’s possible to create a shortcut to delete only the completed / checked off lines (haven’t checked yet, just thinking out loud)? If I don’t get everything on my list, it would be good to keep the unchecked lines.

Personally, I don’t want to reset my shopping list this way. When there are items left on my list that I didn’t buy, it’s generally because I looked them over and decided I didn’t want them. Items like that should be wiped out, which is why I wrote my original Shortcut the way I did.

But I can see how others would like to manage their lists like roguewolf. So I made another Shortcut, named Delete Purchases, that does just that. You can download it or build it yourself from these steps:

StepActionComment
1 Delete Purchases Step 01 Get the current text of Dot 1. Call it “Original list.”
2 Delete Purchases Step 02 Show the current text of Dot 1 in an alert that asks if the user wants to reset it. If the user taps the Cancel button, the Shortcut is aborted. This protects against accidentally resetting a list that’s partially written.
3 Delete Purchases Step 03 Delete all lines beginning with a filled box (■). Call the result “First pass.”
4 Delete Purchases Step 04 If a store name (which is bold) is followed by a blank line, insert an open box and a space (□ ) to initialize the list for that store. Call the result “Second pass.”
5 Delete Purchases Step 05 Replace the current contents of Dot 1 with “Second pass.”

Further explanation of Step 3: If you’re like me, you might be expecting to see the regular expression start with a caret (^) to indicate the beginning of a line. That’s how Unix tools like grep, sed, awk, and Perl work. But in Shortcuts, the caret represents the beginning of the entire input string, so I had to use linefeeds immediately followed by a filled box to indicate a checked-off item.

If you think this Shortcut fits your shopping habits better than the original, thank roguewolf.