I used to install Secrets.app just for this one feature.  This script goes in your Library/Scripts and it will be on the scripts menu to lock and unlock the dock.  Why this feature isn't built in?