I am new to AppleScript, and as part of trying to set defaults for new account(s), i am trying to set the default screensaver via Applescript.
Set default screensaver
Set Hot corners (topright = disable the screensaver & bottomright = enable it)
Start After = 5 minutes
Enable “Show with clock”
Thanks to MacScripter I already found out to do #1
Now i need to find how to accomplish the other ones.
I used to use default writes (plist) but as Apple changes a lot when new versions are coming, i decided that it may be saver to probably use AppleScript, but any advice is welcome
Officially, there are System Events settings for #3 and #4. They weren’t working when I last looked in macOS 10.13.1, but seem to be working in Mojave:
tell application "System Events"
set delay interval of screen saver preferences to 5 * minutes
set show clock of screen saver preferences to true
end tell
Or:
tell application "System Events"
tell screen saver preferences to set {delay interval, show clock} to {5 * minutes, true}
end tell
Apart from ‘main screen only’, other settings still have to be done with “defaults write” (or manually in System Preferences), I’m afraid.
Worked like a charm! Thank you very much, saved me a lot of valuable time.
Cause i already spent about 2 days googling for something where i could find an answer.
I even tried Automator, as some suggested (copy pasting it to Applescript - but way to much i could, yet, make sense of )
Do you, by any chance, know where to find more info about what Applescript can set/configure regarding System Preferences (like the Dock, Trackpad/Mouse, etc…)
There are a few other preferences that can be set using System Events (a scriptable background application), but they’re not particularly comprehensive. There are groups of commands to set preferences (or get information about) accounts, appearance, CD & DVD settings, the Dock, log-in items, network, screen saver etc. etc. If you open System Events’s “dictionary” in Script Editor (File → Open Dictionary …), choose the “View terminology suites” view, and scroll through the list of Suites on the left, you may find a few useful or interesting possibilities.
Otherwise one has to resort to the black arts of running “defaults write” shell scripts or using GUI Scripting (another facility provided by System Events) to imitate clicking things in the System Preferences application. System Preferences itself is scriptable up to the point where you can usually open the view you want, but actually clicking or changing anything in that view requires GUI Scripting.
The disadvantages of “defaults write” are that you have to know what value to write to which key in which domain — which Apple doesn’t make easy — and settings may be moved or ignored in later OS versions. The disadvantages of GUI scripting are that the architecture of the windows in you want to click or set things can vary from system to system — and even from user to user if they’ve set different viewing preferences. But both can be useful from the point-of-view of getting things done, which is what scripting’s about.