Toggle display mirroring

I want to be able to toggle display mirroring on and off. I did a search here and saw a reference to a command line tool to do this but when I run this tool (command or it's corresponding app) it is only able to turn mirroring off. It won't turn mirroring back on. I suppose a change in Catalina has broken the tool (last update looks to be 2 years ago). I ran the code in Xcode and took a look but not being a macOS programmer it isn't clear what has changed that breaks the check for the current state of mirroring. Apparently Command-F1 used to toggle mirroring as well but on my system it doesn't work and in the Keyboard Shortcuts preferences there is no listing for mirroring. Anyway since I haven't found another solution...

I know how to open the Display preferences panel but I don't know of a reliable way to switch to the Arrangements tab and to toggle the checkbox using KM. Has anyone created something like this? TIA!

You might run the free Mirror Displays in an Execute Shell Script action.

That is the one I tried. On my MBP running Catalina it can disable mirroring but it won't toggle back to mirrored. Does it work for you?

On the App Store I found one called "Display Menu" that has menu options which can control mirroring in its free version. I tried it out and it does work. I should be able to use KM to control that app but I need to look into the details as it is a menu bar only app. There is also a Pro version of that app which supports AppleScript.

It turns out the Pro version is only US$1.99 so I purchased it so I can control mirroring and the resolution using an Apple Script triggered by KM. Seems to work fine.

Bravo!