Based on use of sourcehound's 'Mac HelpMate', here are two additional AppleScript code lines.
Code to 'lock' the 'Dock' ...
do shell script "defaults write com.apple.dock contents-immutable -bool Yes; killall Dock"
... save the code as an application (see the process steps of my first reply) and title it something like - 'Dock_locker'
Code to 'unlock' the 'Dock' ...
do shell script "defaults write com.apple.dock contents-immutable -bool No; killall Dock"
... save the code as an application and title it something like - 'Dock_unlocker'
----
Summary:
'Dock_locker' will prevent items being added to / or removed from the 'Dock'. One can still drag items to a 'Dock' based folder or volume.
'Dock_unlock' will allow items to be added to / or removed from the 'Dock'.
-----
A quick (hopefully - 'objectively' taken) observation of 'Mac HelpMate' - only from using the 'Pref' tab's features.
The popup menus do not reflect the current (actually saved) state of the selectable options.
An example - I can have the 'Dock' oriented anywhere (left, right, and even top), Pinning set to 'start', and Minimization set to 'Scale'; but, 'Mac HelpMate's 'Pref' tab's panel will allows display 'Orientation' as 'bottom', 'Dock Pinning' as 'middle', 'Set my Window Minimization Effect to:' as 'Suck', etc. It is as if 'Mac HelpMate' does not view the 'com.apple.dock.plist' file, and set the respective popup menus accordingly.
'
TinkerTool's 'Dock' tab's popup menus do reflect the 'com.apple.dock.plist' setting when launched.