Toggle Mojave's Recent Apps in Dock with AppleScript

I would like to be able to toggle the Dock’s Recent Applications section programmatically using AppleScript.

It works using:


do shell script "defaults write com.apple.dock show-recents -bool " & true
do shell script "killall Dock"

But I wonder what it’s equivalent name is via Dock Preferences and System Events (more elegant), similar to:


tell application "System Events" to tell dock preferences to set magnification to true

show-recents” is the name in the com.apple.dock plist file, but does not seem to work like this:


tell application "System Events" to tell dock preferences to set show-recents to true

Any help would be appreciated. Cheers.

UPDATE: Anybody?

Dock preferences object of System Events application has editable property magnification (this is why you can set its value directly) and some others. show-recents isn’t among them, so:


tell application "System Preferences"
	activate
	set the current pane to pane id "com.apple.preference.dock"
end tell

tell application "System Events" to tell application process "System Preferences"
	repeat until (exists window "Dock")
		delay 0.1
	end repeat
	click checkbox "Show recent applications in Dock" of window "Dock"
	click UI element 23 of window "Dock"
end tell

tell application "Dock" to quit

OR, more shortly (works more fast than killall comand):


do shell script "defaults write com.apple.dock show-recents -bool " & true
tell application "Dock" to quit