I do want to suggest you install termux, and do it from fdroid rather than the play store.
I'm guessing you're on Wayland, so check out ydotool. (If still on x s/x/y) there's a lot of cool things to do with tools like that. Basic one is use your phone as a keyboard (like KDE connect can do, but I found it more reliable and KDEC doesn't play well with VPNs)
I wrote a similar script in Apple Shortcuts and... wtf is this bullshit. My files backup Shortcut is even uglier. I'm incredibly impressed at the hacky shit I was forced to do just to backup photos... I almost would rather pay for an app that does it. I almost would rather learn how to write an iOS app. Just to... replace a 10 line bash script -__-
Since I'm still not a big fan of Google my next phone is going to be a Pixel and I'll install Graphene on day 1. That is, unless something better comes out :)