This recent question was classified as a "duplicate" with existing answers. Two questions were cited as providing answers to the poster's question:
I don't mean to imply that a 5+-year-old question is no longer valid or relevant, but macos has gone through some changes since then. In particular, Apple seems to be less-focused on developers using scripting languages to interact with the system.
Question #1 above has 3 answers. Two of them are for libraries that appear to be no longer maintained (ControlPlane and Network-listener), and the third is for a commercial app (Sidekick) which got few votes, and wasn't selected as "the answer" by the OP.
Question #2 above has 1 answer that has gotten any votes in 5.5 years. In addition, the OP for the "duplicate" question made it clear in an edit that this question was different than the one he asked, and (IMHO) explained that lucidly and convincingly.
In closing, two comments:
I would imagine that marking new questions as duplicates to questions posted years ago might occasionally discourage new, more relevant answers.
It seems that in this case, the question is not actually the same.