Table of Contents

Shortnote

When using multiple machines with screens, it is convenient to have a host-switch to trigger a screensaver across all screens. The following applescript uses Apple Remote Events to turn the screen-saver on multiple machines at the same time.

Setup

To get this working, you will have to enable Remote Apple Events by going to System Preferences→Sharing and ticking the box next to Remote Apple Events.

After that, you must edit the code below and modify the line:

set macs to {"eppc://john:L774d8q9@imac.local", "eppc://jane:084gr2b9@macbook.local"}

in order to set-up the machines on which the screen-saver should be triggered.

In this example, the screen-saver "Flurry" will be triggered on the machines:

It assumes that the imac.local machine has a user john with password L774d8q9 and that the machine macbook.local has a user jane with password 084gr2b9.

You can add as many machines as you like, for example:

set macs to {"eppc://john:L774d8q9@imac.local", "eppc://jane:084gr2b9@macbook.local", "eppc://jess:5k1b3jj1@mini.local", ... }

Code

synchronize_screensavers.applescript
-- Copyright © 2012 Wizardry and Steamworks @ http://grimore.org 
-- GNU General Public License v3 
-- Please see http://www.gnu.org/copyleft/gpl.html
--
-- This script requires you to activate remote apple events
-- On all machines that you want to turn on the screen-
-- saver. You can do so by going to System Preferences -> 
-- Sharing and then turning on "Remote Apple Events".
-- 
-- Add your own machines to the macs list. 
-- The format is: eppc://username:password@computer
-- 
-- The example below will trigger the "Flurry" screen-
-- saver on the imac.local and macbook.local machines.
-- The imac user is "john" with password "L774d8q9" and 
-- the macbook machine user is "jane" with password
-- "084gr2b9". You must edit these and change them to 
-- the usernames and machines on your network.
--
-- For more information, please see:
-- http://grimore.org/osx:synchronize_screensavers
 
-- Edit this to add your computers.
set macs to {"eppc://john:L774d8q9@imac.local", "eppc://jane:084gr2b9@macbook.local"}
-- End edit.
 
repeat with mac in macs
	using terms from application "Finder"
		tell application "Finder" of machine mac
			open application file id "com.apple.systemevents"
		end tell
	end using terms from
	using terms from application "System Events"
		tell application "System Events" of machine mac
            -- You can set a different screen-saver here
            -- instead of Flurry. For example, Random could
            -- be used instead.
			set lock to screen saver "Flurry"
			start lock
		end tell
	end using terms from
end repeat

Alfred

Alfred is a Spotlight replacement that allows custom extensions to be added in order to create handy macros. Using the AppleScript, we can create a new macro that will turn on screen-savers on all configured machines using the keyword lockdown.

Download Extension

You can download the latest version of the extension here:

Sleep

This variation allows you to make all the machines sleep simultaneously. This can be combined with the System Setting to immediately ask a password after sleeping.

synchronize_screensavers.applescript
-- Copyright © 2012 Wizardry and Steamworks @ http://grimore.org 
-- GNU General Public License v3 
-- Please see http://www.gnu.org/copyleft/gpl.html
--
-- This script requires you to activate remote apple events
-- On all machines that you want to turn on the screen-
-- saver. You can do so by going to System Preferences -> 
-- Sharing and then turning on "Remote Apple Events".
-- 
-- Add your own machines to the macs list. 
-- The format is: eppc://username:password@computer
-- 
-- The example below will trigger the "Flurry" screen-
-- saver on the imac.local and macbook.local machines.
-- The imac user is "john" with password "L774d8q9" and 
-- the macbook machine user is "jane" with password
-- "084gr2b9". You must edit these and change them to 
-- the usernames and machines on your network.
--
-- For more information, please see:
-- http://grimore.org/osx:synchronize_screensavers
 
-- Edit this to add your computers.
set macs to {"eppc://john:L774d8q9@imac.local", "eppc://jane:084gr2b9@macbook.local"}
-- End edit.
 
repeat with mac in macs
	using terms from application "Finder"
		tell application "Finder" of machine mac
			sleep
		end tell
	end using terms from
end repeat