Main Content

Changing a screen saver from a web page (PHP, Perl, OSX)

Archive - Originally posted on "The Horse's Mouth" - 2008-05-06 17:49:19 - Graham Ellis

Here's a challenge. I want to change the screen saver on a mac mini, running OSX, from a browser anywhere in the world.

You may well ask why ... the screen of the mac mini is to be visible at Well House Manor where it will provide an information screen at the front door when it's not otherwise in use, and we want it to say things like "Sorry - no Vacancies" and "Welcome to the Chamber of Commerce"

Task achieved! Using PHP ... and Perl ... and Web2 technology. With a smattering of OSX!

Here's the control widget on our web page ... the page is in PHP and this particular widget is only displayed to staff members who are logged in - if you look at our Staff Resources Page you won't see it.

And the PHP that's run when you press the update button:


if ($_POST[door] == 12) { // Door Status changed
  $ds = $_POST[doorst];
  $fho = fopen("door.txt","w");
  fputs ($fho,stripslashes($ds)."\n");
  fclose ($fho); // Host and Port changed for security
  $done = file("http://zzz.wellho.net:8080/cgi-bin/dodo.pl?$ds");
  }


That piece of viewing software was called a controller on the Mac - which is running as a Web Server on a port enabled on our firewall, and redirected with NATS to the Mac Mini.

The Perl software dodo.pl looks like this:

#!/usr/bin/perl
print "content-type: text/html\n\n";
print "Changing Page";
`rm -rf /Users/lisaellis/FrontDoor`;
`cp -r /Users/lisaellis/$ENV{QUERY_STRING} /Users/lisaellis/FrontDoor`;
open (FH,"ps aux|");
while (<FH>) {
  if (/ScreenSaverEngine/) {
  @n = split;
  kill 9,$n[1];
  print "$n[1]<br>";
  }
}
sleep 1;
open (FH,'|/System/Library/Frameworks/ScreenSaver.framework/Versions'.
'/A/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine' );
close FH;
print "Changing Page";


And there's also a standalone version here if you want to download a copy for your own use.

You'll notice - typical use of PHP to front a web application, typical use of Perl as "glueware", and typical use of a Unix / Linux / OSX utility - in this case Mac's ScreenSaverEngine - to do the oddball job we needed.