Thanks for sharing this. I think many Mojave users will find this useful. Out of curiosity, why did you limit this to Mojave (and above) ? High Sierra has dark mode too—in a more limited capacity—and it is set via AppleScript using exactly the same code.
I see the macro starts off by executing an AppleScript, then breaking out of it to do a regular expression search before going back in to another AppleScript. As a small hint or tip, you can isolate the major version number like so:
set text item delimiters to "."
set OSMajorVer to text item 2 of system version of (system info)
Then, of course, follow it with:
if the OSMajorVer < 14 then return false
tell application "System Events" to tell ¬
the appearance preferences to ¬
set dark mode to not dark mode
Forgive me if you already knew about
text item delimiters and simply chose to use more core KM actions out of personal preference.