I really want to like Shortcuts, but all I can think about is how much simpler this action would be if I could just write some Swift code for it.

Maybe Shortcuts needs to Run Playground action added to it.