That GUI scripting solution link was done five years ago and that is the least favorable AppleScript solution owing to Apple's continuous changes to the operating system that break that type of code. I will not waste any more time on tinkering with GUI AppleScript grayscale tinkering, especially with Ventura where the Settings are completely scrambled.
If you have Python3 installed, either from Apple's CommandLine Tools for Xcode, or from Python.org, then the following script will toggle grayscale on Monterey 12.6.3 (tested) or Ventura 13.2 (tested). Tested with Python 3.9.6 and 3.11.1 on both operating systems.
Since this script is loading a private Apple framework and methods — it may also break eventually.
use scripting additions
-- reference: https://indiestack.com/2019/04/toggle-system-grayscale-mode/
-- Line up a Python script for dynamically loading
-- the private framework and invoking the required
-- private methods to get current grayscale mode
-- and set it to the opposite value.
if exists "/usr/local/bin/python3" then
-- have installation from Python.org
set PYTHON3 to "/usr/local/bin/python3"
else if exists "/usr/bin/python3" then
-- have installation from Apple's CommandLine Tools
set PYTHON3 to "/usr/bin/python3"
else
display dialog "Missing Python3… script ending." giving up after 10
return
end if
set toggleGrayScript to PYTHON3 & " -c 'from ctypes import cdll
lib = cdll.LoadLibrary(\"/System/Library/PrivateFrameworks/UniversalAccess.framework/UniversalAccess\")
lib.UAGrayscaleSetEnabled(lib.UAGrayscaleIsEnabled() == 0)
'"
do shell script toggleGrayScript
return