Thanks, I appreciate thatIt is an admirable work, with ingenious solutions. But because it uses clicks in System Preferences, it might only work properly on macOS 10.13.6.
On Monterey for example, it randomly returns “System Preferences got an error: Can’t get current pane.” and other errors.
More, on laptops without an Ethernet port, Wi-Fi is en0, not en1.
Fortunately, networksetup gets past that and returns: "en1 is not a Wi-Fi interface. Turning off the only airport interface found: en0"
In the end, it works as you want it and it provides a good template for anybody with a similar problem. 👍
In this (and similar ones I've done) I consider myself more as an "information collector/administrator" as I only understand partly what's going on with the coding and don't have the abilities to do it from scratch. But patience, testing and having a clear idea of what I want done helps
And in the end I learn a lot from your and others' help in this thread, which is info I can use in the next project.
I didn't know about that ethernet port thing. Fortunately I have the script working fine on both a Macbook Pro and a Mac Pro. And like you say it could provide as a template for a similar issue (or hopefully to get my next project going).