Two things could prevent the writing of the preference. If SIP isn’t verified to be disabled, that’s a blocker. Also, if you don’t see the preference set after a restart, there’s an issue with the defaults write command.
Is SIP disabled?
To be able to run that command you must first disable System Integrity Protection. That answer links to it here: Configuring System Integrity Protection.
If it's enabled you won't be able successfully run the
defaults write ... command.
$ csrutil status
System Integrity Protection status: enabled.
You'll get a failure message like this:
$ sudo defaults write /System/Library/LaunchAgents/com.apple.OSDUIHelper \
Disabled -bool YES
2019-04-19 16:53:21.310 defaults[92957:2162882] Could not write domain /System/Library/LaunchAgents/com.apple.OSDUIHelper; exiting
To disable/enable SIP:
To enable or disable System Integrity Protection, you must boot to
Recovery OS and run the csrutil(1) command from the Terminal.
- Boot to Recovery OS by restarting your machine and holding down the Command and R keys at startup.
- Launch Terminal from the Utilities menu.
Enter the following command:
$ csrutil enable
But I have SIP disabled
If you've confirmed that SIP is disabled then you could use
opensnoop to debug what's going on to gain additional insight as to why your
write command is failing.
For example, in one terminal run this command to snoop:
$ sudo opensnoop -ve |& less
And in another window try running your
defaults write ... command:
$ sudo defaults write /System/Library/LaunchAgents/com.apple.OSDUIHelper Disabled -bool YES
2019-04-19 17:23:53.712 defaults[94310:2174907] Could not write domain /System/Library/LaunchAgents/com.apple.OSDUIHelper; exiting