10.5: Create an XKCD-influenced Mac 'doorbell'

Jan 21, '09 07:30:00AM

Contributed by: vivekv80

A friend of mine wrote recently on his blog:

Randall Munroe's XKCD has inspired interesting product features in the past. A recent one has sent a lot of Mac users scurrying to set up an audio doorbell on their Mac Minis.
Here's his solution to the problem; paste the following code into a text editor and save it as, for example, say.php in the top-level /Library » WebServer » Documents folder of the Mac you wish to turn into the doorbell:
<?php
if (isset($_GET['say'])) {
  $cmd = sprintf('say "%s"', preg_replace('/[^\w\d ]/', '', $_GET['say']));
  `$cmd`;

} else if (isset($_GET['up'])) {
  $cmd = 'set output_vol to output volume of (get volume settings)
  set volume output volume (output_vol + 10)';
  `osascript -e "$cmd"`;

} else  if (isset($_GET['down'])) {
  $cmd = 'set output_vol to output volume of (get volume settings)
  set volume output volume (output_vol - 10)';
  `osascript -e "$cmd"`;
}
?>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">
  <p><input type="text" name="say">
  <input type="submit" value="Say"></p>
  <p>Volume:
  <input type="submit" name="up" value="Up">
  <input type="submit" name="down" value="Down"></p>
</form>
<p>Hey Randall, here's how you
  <a href="http://xkcd.com/530/">change the volume</a>.<br/>
  &ndash;<a href="http://manas.tungare.name/">Manas</a>.
</p>
To test from the Mac your created the file on, make sure Web Sharing is enabled in the Sharing System Preferences panel, then load http://localhost/say.php in your browser. To access the "doorbell" from another machine on the same network, use the Bonjour name (as shown in the Sharing System Preferences panel) instead: http://My_MacPro.local/say.php.

For a more detailed walk through, see the original post on my friend's blog.

[robg adds: We've had a lot of hints on using say in Terminal, but as far as I can tell, we've not run anything about changing the remote Mac's volume settings.]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090115035623911