Introduction:
I have tried a few things over my local network. My attempt to run a remote AppleScript nearly shutdown the Mac I was activating it from. There are probably ways around this but I decided to try something else.
The following is a very stable solution once you have got it working. Each Mac to be shut down watches a folder called shut-down and if its contents change the Mac shuts down in one minute.
I am sure this can be improved upon.
Let me know how you get on.
Permissions:
It is simple to do all this as root user as described below but without 'with administrator privileges' at the end of the AppleScript.
If doing it as admin use the AppleScript as below. The plist may need permissions set to root wheel.
The shut-down folder will need appropriate sharing permissions.
Create plist etc:
open TextEdit
create a new document
set TextEdit format to plain text
copy plist contents below
paste into the TextEdit document
save as shut-down.plist
put document in folder /Library/LaunchAgents on each Mac to be shut down
create folders entitled shut-down at the root of Macs to be shut down
run launch AppleScript below on each Mac to be shut down
Future changes to the shut-down folder's contents will shut down the Mac.
Contents of shut-down.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>shut-down</string>
<key>ProgramArguments</key>
<array>
<string>shutdown</string>
<string>-h</string>
<string>+1</string>
</array>
<key>WatchPaths</key>
<array>
<string>/shut-down</string>
</array>
</dict>
</plist>
Launch AppleScript:
Put the following on one line;
do shell script "launchctl unload -w /Library/LaunchAgents/shut-down.plist; launchctl load -w /Library/LaunchAgents/shut-down.plist" with administrator privileges