Kit has to be given permission for System events in Settings -> Security & Privacy -> Privacy -> Automation

// Menu: Switch osx theme
// Shortcut: option command t
// Author: Oskars Ezerins
const toggleTheme = async () => {
let script = `
tell application "System Events"
tell appearance preferences
set dark mode to not dark mode
end tell
end tell
`.trim()
return await global.applescript(script)
}
toggleTheme()