Script to dim the display

I want a script that dims the display as much as possible.

Google said that the script below should work, but it doesn’t do anything for me. Do I need to modify it to work in Catalina?

tell application "System Events"
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
	key code 107
end tell

How about brightness tool?
https://github.com/nriley/brightness

I use it from AppleScript
http://piyocast.com/as/archives/8821

The brightness utility is very useful, so it’s worth installing. I would just like to point out that plain AppleScript can do this too (using GUI scripting, but not as tried the OP):


-- script: DIM THE DISPLAY

-- In the Keyboard preferences:
--        set checkbox "Use F1,F2, etc. keys as standard function keys"

-- In the Accessibility anchor of Security & Privacy:
--        allow to frontmost application to control your computer

tell application "System Events"
	key down 63 -- holding Fn key
	repeat 16 times
		-- gradually decreaze the brightness
		key code 145 -- to increaze, use 144
	end repeat
	key up 63
end tell

If someone has a solution to this simple task without a third-party utility and GUI scripting, then I would be grateful for posting it in this topic.