Toolbox Pro’s Add To List

I don’t understand how Toolbox Pro’s Add To List action works in a repeat loop. Here’s an example:

The list starts with a single text item, “Initial”, and then I repeat the addition of the text “Repeat” four times. What I expect to end up with is a five-item list:

Initial
Repeat
Repeat
Repeat
Repeat

But what I get is this:

It’s adding “Repeat” to the end of the list and then replicating that two-item list four times. Why is it doing that?

This reminds me of the need to re-instantiate a Dictionary every time you change or add to it.

Maybe add a new “Make List” / “save to variable” action after the Toolbox Pro one? (I can’t actually check what that action should be right now, as the latest beta has literally removed all of my possible Shortcut actions except for Siri Suggestions… :upside_down_face:)

It’s doing that because you take the initial list four times and add repeat to it to effectively create four lists each containing two entries; which the app will then simply treat as. single list of eight items.

If you want to append to a single list, you need to put the resulting list somewhere each time. You need to set it within the loop rather than just generating a value in the loop.

Hopefully this will help.

https://www.icloud.com/shortcuts/8690ef3bbedd41bf8be99c967bc3bbd0

Note the result of adding to the list is a new list … not nothing with the old list having been updated. That’s where we can come back to using non-magic variables. Not everything can be magical.

3 Likes

That’s definitely what it’s doing, but I wouldn’t have guessed it from the action’s description. Thinking about it more carefully, though, it does make sense that you can’t change a magic variable. I have a feeling ‘Add To List‘ wasn’t built with the idea of using it in a loop, because it creates a new list with every pass.

1 Like

It works the same way as the native add to variable and add to dictionary actions. It is just how the ‘Shortcuts language’ works - things you might do horizontally in a single line in other languages you have to do vertically in Shortcuts as the outputs of operations are passed down rather than across.

1 Like

I do this to create joined lists - not sure if the text coercion will work for your specific use case but works more often than i expect it to!

1 Like