Enable macOS "Dark menu bar and Dock" without password or restarting
Unfortunately, changing system preference files will always require administrative permissions, which is something the user has to explicitly give your script.

Fortunately, there is a way to accomplish this without changing system preference files! Using AppleScript, one can ask the system event daemon to change the system appearance.

I'm testing this on my work laptop, which doesn't allow me to change Accessibility preferences, so I don't even know if Terminal is enabled there (I suspect it's not). Additionally, this does not do any GUI scripting! (I recorded the below gif with System Preferences not running) Instead, it performs the same action that checking the box in System Preferences performs, but without needing access to that checkbox.

Hope this works for you!

AppleScript

-- Toggle dark mode
tell application "System Events" to tell appearance preferences to set dark mode to not dark mode

-- Enable dark mode, even it it's already enabled
tell application "System Events" to tell appearance preferences to set dark mode to true

-- Disable dark mode, even it it's already disabled
tell application "System Events" to tell appearance preferences to set dark mode to false


Bash

Don't wanna have something kick off an AppleScript? I'm with you. You can execute any AppleScript from bash (and thus the terminal) passing it as a string to the osascript -e command:

# Toggle dark mode
osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'

# Enable dark mode, even it it's already enabled
osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to true'

# Disable dark mode, even it it's already disabled
osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to false'






I have made a proof-of-concept app that shows off this technique, plus a couple others:

macOS Dark Mode Switcher