HOWTO Make your Mac speak over the Web

15 Jan, 2009 — Apple, Funny, HOWTO

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 how you can do it.

The Source Code

<?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>

Where to Put It

Copy the code to a new file, name it “say.php” (or whatever else you want to call it) and put it in Macintosh HD /Library/WebServer/Documents/. Remember, this is the top-level /Library directory, not the one under your own user account. You also need to make sure that Web Sharing has been turned on under System Preferences > Sharing.

How to Use It

Open a browser, and type in:

http://localhost/say.php

from your own machine.

To do this from another machine connected to the same router, use the Bonjour name of your Mac (this can be found under System Preferences > Sharing.) E.g.

http://Manas-Desktop.local/say.php

To do this from a machine outside your router, you need to have configured your router correctly. And if you can do that, you don’t need me to tell how to do the rest of it.

Bonus feature: this script also lets you increase and decrease the volume. Perhaps then, Randall’s roommate might have heard him.

Screenshot

Warning: Security Issues

To achieve what this script does, it needs to take input from the Web and use it in a command that executes in a shell. The input is sanitized and I believe that such a risk is minimal. However, if you’re concerned about this possibility, do not install this script. You are responsible for what you do with this script and your machine. If you’re really concerned, put it inside an authenticated session.

Update: Added a command injection filter suggested by Mac OS X Hints user skicker.

Why I love working here!

27 Aug, 2008 — Academic, Funny, Life

When most professors have closed-door policies and need weeks of lead time before being able to schedule a meeting, here’s why I love working here!

Who's Online?

Readymade luggage kits for baggage-less air travelers

7 Apr, 2008 — Funny, Life, Thoughts

Now there’s a business opportunity that today’s airline industry and airports have created: why not sell pre-packaged suitcases at airports to scalp travel-weary passengers whose luggage has landed in Murmansk?

Here’s how it would work: I’d walk up to the Lost and Found desk of the airline, usually fortified behind several layers of arrows pointing upward, downward, or in all other sorts of directions in which I cannot walk; barriers laid down with those flexible tapes that you can simply unhook and pass through; or behind a scruffy-looking bouncer. They would then cheerfully inform me that my luggage has, indeed, failed to follow me around in my travails around the world, and make me fill out a 3-page form describing my “small black bag” in as many words. After a state of shock, worry, desperation, and finally, anger, I would quit discussing this with the airline folks and move on, resigned to my fate.

That’s when I would notice the conveniently located “Missing Luggage Mart”. I’d turn to the enterprising store-owner and tell him/her my size, and the duration of my trip. He/she would whip out a readymade suitcase of shirts, t-shirts, trousers, undergarments, socks, shorts, a belt, a cellphone charger, a toothbrush, a toothpaste, a tiny bottle of shaving cream, a tiny bottle of shampoo, etc., and I would be on my own merry way.

And a towel, of course. Nobody should ever be without their towel.

Google all the way … in a scary way!

1 Apr, 2008 — Funny, Google, Life, Sightings

Google recruiters use Google to search for recruits for Google. And how do I know? I found out because of another Google product. The irony is that I’ve been at Google, and I will be at Google, so I’m not exactly who they’re looking for. So, all this, and the search was a failure, then?

Here’s what happened: I’m in the habit of checking my web server logs every once in a while to see which pages are popular, where my users are coming from, what keywords they type into search engines to find me, and sometimes just to stalk my stalkers. ;) For this, I use two great tools, StatCounter and Google Analytics. (StatCounter is the better of the two, by the way, but they have a last-500-visitor limit, so I need to check my stats at least daily.)

Today, the following entries appeared in my logs:
(inurl:resume or intitle:resume or inurl:cv or intitle:cv) (c or c++ or java) “computer science” “software engineer” (415 or 650 or 925 or 510 or 408 or 369 or 669 or 707 or 831 or 916 or 530) -jobs -job

The IP addresses show that the request came from Google’s Mountain View headquarters. The query shows exactly who they’re looking for. Interestingly, they seem to be hiring locally (the numbers in parentheses are all telephone area prefixes in the San Francisco Bay Area.)

There’s so much Google involved in this story, it’s scary.

A German, a Brazilian and an Indian walk into a Conference

8 Dec, 2007 — Funny, Life, Thoughts

A German, a Brazilian and an Indian, all three student volunteers, walked towards the conference office the day before a conference. As it happened, the student volunteer chair had had some trouble reaching the venue, and there were no specific instructions for the volunteers at that time. Nobody else had any information or any plan to hand out either. (Turns out they did, but our protagonists did not know at the time.)

The German noted this and wondered how they could be so ill-prepared and without a plan just one day before the conference. The Indian remarked that they might just be running late and here’s hoping that everything would be fine and dandy by the next day, the day of the conference. The Brazilian said, oh well, if they don’t have anything for us to do, we’ll just go to the beach and have fun instead.

While this anecdote might not have had the punchline you might have been waiting for, (especially given the clichéd setup), it’s a nice illustration of how cultural upbringing shapes our thinking in the most trivial of incidences in life.

Next Page »