Opening File One a A Time Then closing the App

Hey Keane,

That's about a half hour job (or more) for someone not readily familiar with scripting the system preferences.

For that matter you DON'T want to use System Events to UI-Script the prefs.

This will set the start time of the screen saver to none:

tell application "System Preferences" to if running then quit

tell application "System Events"
  tell screen saver preferences to set its delay interval to 0
end tell

The following shell script will set the sleep interval to “never”.

sudo pmset sleep 0

You can make this run without having to enter your password by adjusting your sudoers file.

(I haven't done this, so you'll have to research it yourself.)

If you're willing to enter your username and password in a script then you can combine the above by running this AppleScript:

tell application "System Preferences" to if running then quit

tell application "System Events"
  tell screen saver preferences to set its delay interval to 0
end tell

do shell script "sudo pmset sleep 0" user name "yourUserName" password "yourPassword;" with administrator privileges

This trounces sluggish GUI-Scripting.

References for Learning and Using Applescript

See in particular the Online Applescript Communities section.

For more than you want to know see:

Learning & Using AppleScript & JavaScript for Automation (JXA)

-Chris