Is there a way to set Screen Saver time to Never by Keyboard Maestro?

Is there a way to set Screen Saver time to Never by Keyboard Maestro?
and to "20 minutes" ?

The MacScripter site has an AppleScript that will work.

In Keyboard Maestro, these AppleScripts can be run using the Execute An AppleScript action.

The script for a 20-minute delay looks like this:

tell application "System Events"
   tell screen saver preferences to set {delay interval} to {20 * minutes}
end tell

The script for the Never setting would be identical, with the one change being 20 becomes 0.

For example:
image

2 Likes

Shell script version, which will toggle between "Never" (0 seconds) and "20 minutes" (1200 seconds). Set the hot key trigger to whatever suits:

Toggle Screensaver.kmmacros (1.8 KB)

1 Like

Thank you both! It seems neither of this two option works for me , probably because I'm on Ventura and Mac changed the way for screen saver count down, previous the timer is in Screen Saver but now in Lock Screen.

Doesn't work in what way? You can't rely on System Settings immediately reflecting the changes, but Screen Saver Engine should respect the new settings.

Thanks but I like the System Setting to reflect the change...
I suppose there's no direct way in Keyboard Maestro instead using Apple Script?

Correct.

That's just the way macOS prefs work now -- they are cached, rather than constantly evaluated, so when you make a change outside of System Settings you often have to Quit and re-Open for it to show.

You can force a cache reset by adding killall cfprefsd to the end of the script -- so the full thing would be:

if [[ $( /usr/bin/defaults -currentHost read com.apple.screensaver idleTime ) == 0 ]]
then
	defaults -currentHost write com.apple.screensaver idleTime -int 1200
else
	defaults -currentHost write com.apple.screensaver idleTime -int 0
fi
killall cfprefsd

Tested and working on my macOS Ventura 13.3.1

Toggle Screensaver with Refresh.kmmacros (1.8 KB)

Image

1 Like