HOWTO Make your Mac speak over the Web

Permanent Link | Filed under: Apple,Funny,HOWTO
15
Jan
2009

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

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

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

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

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.

An awesome “prank” on the Virginia Tech campus

21
Oct
2007

I received the following email a few minutes ago, with fake headers and the works, and is formatted exactly the same way as the regular email we get from these folks. It’s probably viral marketing for the upcoming game, Portal, releasing November 23, 2007. Lots of references to it in the text.

1. UNDERGROUND HALLOWEEN ADVENTURE
2. BOBBY FISCHER – ENDED THE SOVIET CHESS HEGEMONY
3. SELECTING YOUR CABLE COMPANY IN BLACKSBURG
4. PI EATING CONTEST
5. POSSIBLE BAG BAN
6. DONALDSON-BROWN LOCKS TO BE CHANGED
7. ODD – OPEN DOOR DAY
8. MICROSOFT VISTA SERVICE PACK DEMO
9. WEEKLY SPEAKER SERIES
10. REGISTRATION FOR DEAN’S FORUM ON HEALTH, FOOD AND NUTRITION
11. STUDY PARTICIPANTS NEEDED

1. UNDERGROUND HALLOWEEN ADVENTURE
A Halloween tour of the steam tunnels beneath campus will be offered for the first time this year to four groups of eight people on Oct. 29th and 30th. Sign-up for each of the four tours will begin on Monday, October 22nd, and continue until all places are taken. Interested parties should contact Richard McCoy at 231-3200 for more information.

2. BOBBY FISCHER – ENDED THE SOVIET CHESS HEGEMONY
Monday, Oct 22, 5:30-7:00 in Williamsburg Rm, 7:00-8:00 in Haymarket Theater in Squires Center The man who ended the Soviet chess hegemony by defeating Boris Spassky will speak at Virginia Tech. A reception will precede his presentation at 7:00pm. Robert James “Bobby” Fischer is a United States-born chess Grandmaster who in 1972 became the only US-born chess player to become the official World Chess Champion. Fischer’s victory during the Cold War caused a great interest in chess and is responsible for the swelling of members of the World Chess Federation.

3. SELECTING YOUR CABLE COMPANY IN BLACKSBURG
Sometime between Tuesday, Oct 23 08:00am and next Friday, Nov 2 7:00pm in Room C in the GLC Are you interested in purchasing a subscription package from your local cable company? Presenters from NTC Communications Comcast Digital Cable and Cox Communications will talk about the different internet, phone and cable packages available and answer questions about rates and programming.

4. PI EATING CONTEST
Tuesday, Oct 23, 7:00pm in Room F in the GLC the VT Math club is sponsoring a Pi festival. Approximately 3,141 pies will be available for sampling. They will include but are not limited to Apple, Banoffee, Banana cream, Blackberry, Blueberry, Cheesecake, Cherry, Chestnut, Cream, Custard, Grape, Lemon meringue, Peach, Pecan, Pumpkin, and Rhubarb. In addition, at 7:30 there will also be a pie eating contest. The first contestant to eat an irrational number of pies will receive a hand-carved Penrose triangle.

5. POSSIBLE BAG BAN
Due to the heightened security of many university campuses, a possible ban of all bags on campus may be implemented in the next two weeks. Backpacks, duffels, shoulder-bags, and purses may soon join the list of items prohibited on campus. This measure has been proposed since it has been pointed out that bags may be able to conceal already illegal items. An unlikely supporter of the ban is the campus Health and Safety Department as it would also alleviate the troubling phenomenon of overweight book bags that commonly lead to health problems later in life. Acceptance of the proposal will be decided by the campus Board of Directors later this week.

6. DONALDSON-BROWN LOCKS TO BE CHANGED
It has come to the attention of university security personnel that many graduate students have access to the GLC 24 hours a day. In order to remedy this threat to campus security, all doors to the GLC will have their locks changed between Monday evening and Tuesday morning. In addition, Donaldson Brown dorm rooms will also have their locks changed on a short rotation. You may need to request a new room key from your Residential Fellow.

7. ODD – OPEN DOOR DAY
To help promote social interaction amongst the graduate students, Thurs, Oct 25, will be open door day. Graduate students on campus are encouraged to keep their door open and meet their neighbors as well as their Residential Fellow if they have not done so already. We are aware that the doors in the GLC rooms close on their own, this is why you have been provided with doorstops. Use them! Hopefully open door day will become more routine and no longer considered odd.

8. MICROSOFT VISTA SERVICE PACK DEMO
Wednesday, Oct 24, 6:00-7:00pm in McBryde 666, Microsoft will be giving an exclusive preview of service pack one for Vista. In response to the massive number of problems, compatibility, and stability issues in Vista, Microsoft has spent the past year fervently addressing these issues in the much anticipated service pack 1 (SP1). Representives from Microsoft will demonstrate the features and stability changes of SP1, such as the newly bolstered DRM software. This update and others in SP1 that will be demonstrated should help provide Vista users with new enhanced reduced functionality.

9. WEEKLY SPEAKER SERIES
Friday, Oct 26, 4:00-5:00pm in Room F in the GLC Faculty speaker: Dr. Henry Warren – Physics, on Structure of the Proton. Graduate students and faculty from across the university present weekly their teaching and research passions in a casual, coffee house atmosphere. Free coffee and pastries served from 3:45pm.

10. REGISTRATION FOR DEAN’S FORUM ON HEALTH, FOOD AND NUTRITION
Registration for the Nov 5 forum is now open. This forum will showcase health, food, and nutrition efforts in research, extension/outreach, and teaching currently underway at McDonalds, Kraft Foods, Monsanto, and LuthorCorp. Register by Sunday, Oct 28 if you plan on attending the event. Sponsors will showcase the health benefits of the latest developments in GMOs, growth hormones, preservatives, artificial sweeteners, hydrogenated oils, flavoring and texturizing food additives. For more information, including registration links, and to view the Forum agenda, please visit http://www.mcvideogame.com/index-eng.html

11. STUDY PARTICIPANTS NEEDED
A graduate student researcher working on behalf of Aperture Science is seeking highly-motivated individuals in good physical condition between the ages of 18-25 for her study. Participants will be asked to perform complex tasks. The entire study should last a minimum of 3 hours and moist, delicious cake will be served upon successful completion of the test. For further information or to sign up to participate, please contact Glados, glados@aperturescience.com

A Heads-Up Display for Social Networks

20
Oct
2007

I often find myself talking to people who I should know (in theory), but for some reason, in practice, my neurons refuse to make the right connections to remember these connections. Wouldn’t it be great if someone designed a heads-up display based on your social network?

This is how it would work: when I activate it, and it notices I’m talking to someone, it would do a quick scan and tell me his/her name. That would be a life-saver, and would avoid the first five minutes of the 20-Questions game I have to play every time this happens (while making sure that the other guy (or girl!) doesn’t notice I’m playing the game in my mind.)

It could also tell me how I know that person, because sometimes I remember the name, but nothing else. Wouldn’t it be helpful to know that I’m talking to John Doe, who went to the same high school as I did, and who is now President and CEO of a Fortune 100 company (note to self: graduate soon.)

Not just names, it could even tell me more about the person I didn’t already know (or, in the more likely case, I’ve forgotten.) I’d love to know that my friend John Doe is no longer with his (now ex-) girlfriend Jane, so that would cut out a lot of awkward conversation. Knowing that he just went on a cruise to Alaska would instantly give us a topic to chat about. Knowing that the lady on his arm is not his wife would probably also help. I could ask him about our common friends and if he were in touch with any of them. And then he could use his heads-up display to pull their details up and tell me what I’d already looked up, but that’s another story.

So why isn’t something like this on the market yet? I’m sure there would be throngs of people lined up outside the offices of the company that makes the first such thing. And if they try to patent it, you can cite my blog post as prior art. You’re welcome. :)

Update: A picture is worth a thousand words. A movie, perhaps a million?

How many languages does it take to change a Keynote slide?

30
Sep
2007

I was playing with Telekinesis on Friday, which lets you use an iPhone as a remote control for your Mac. The idea is simple: Telekinesis runs a web server on your machine, and the iPhone connects to it. It ships with a few Telekinesis Applications (or “tapps”), or you can write your own to control your own programs.

I wrote one to control Keynote presentations from your iPhone. It’s fairly simple: it shows you the current slide and the presenter’s notes for that slide, and it lets you go forward and backward through your slide deck. (No, it’s not release-quality yet, but expect it in a few days.)

So here’s the real meat of this blog post: (Warning: geeky-acronym-land ahead.)

  • Being a Mac OS X app, Telekinesis’s UI is written in Objective C.
  • It exposes a web server that can run PHP scripts.
  • My remote application is a set of PHP scripts that sit on the Mac and run when the iPhone user launches the app.
  • On the iPhone, the user makes a request to the PHP script, that generates HTML, CSS and JavaScript to format the page for the iPhone
  • To capture the current slide, I use a command line program (screencapture) inside a shell script from within PHP.
  • I resize the large slide for the iPhone using another shell script, and push it out to the phone as a stream of bytes, via PHP.
  • To change slides, the user clicks the Next and Previous functions on the iPhone, which use AJAX (JavaScript, XML, XmlHttpRequest) to send the request to a PHP script;
  • the PHP script interprets this request, and wants to use AppleScript to ask Keynote to update the current slide. But since there is no direct way to invoke AppleScript from PHP, we use the command-line tool osascript in a shell script to run our AppleScript.
  • Keynote hears the call to action from our AppleScript, and changes the slide.

So, our champion team now includes the following players: Objective C, PHP, HTML, CSS, JavaScript, Shell Script, and AppleScript: all with the single goal of changing a Keynote slide.

Has anyone changed lightbulbs with an iPhone yet?

Never Lose Your Sense of Humor …

29
Jun
2007

Reuters reports that a man set for execution wants to die laughing. Then he must be told the Funniest Joke in the World, of course!

P.S. I know this is no laughing matter, but I respect a person who manages not to lose his sense of humor even under trying times.

Monty Python’s Killer Rabbit Squirrel in Berlin

17
Jun
2007

And you thought Monty Python were just fooling around when they crafted this scene of the Killer Rabbit in the Holy Grail movie!

Apparently, there is (technically, was) a squirrel on a similar rampage in Berlin this week.

BERLIN (Reuters) – An aggressive squirrel attacked and injured three people in a German town before a 72-year-old pensioner dispatched the rampaging animal with his crutch.

The squirrel first ran into a house in the southern town of Passau, leapt from behind on a 70-year-old woman, and sank its teeth into her hand, a local police spokesman said Thursday. With the squirrel still hanging from her hand, the woman ran onto the street in panic, where she managed to shake it off. The animal then entered a building site and jumped on a construction worker, injuring him on the hand and arm, before he managed to fight it off with a measuring pole.

“After that, the squirrel went into the 72-year-old man’s garden and massively attacked him on the arms, hand and thigh,” the spokesman said. “Then he killed it with his crutch.”

Riding the Google “Conference” Bike

16
Jun
2007

Everyone agrees meetings aren’t fun, but what if you’re discussing matters with your teammates while pedaling a 7-person bike furiously on the streets of Mountain View? Forget the discussing matters part, but the rest of it sure is a lot of fun.

Just don’t call it the party bike; it’s the “conference” bike. Google’s newest acquired toy is a 7-person bike, much like New York City’s Party Bike [link broken at the time of posting]. It can be scheduled as a conference room for holding meetings and as a team-building exercise (no pun intended).

Our team rode the bike to the nearby Shoreline Lake on a hot Friday afternoon. Just for kicks, we rode it up a hillock and let it go full speed downhill. Here’re some action shots!

The Conference Bike
chiu-ki-and-i.jpg


Bookmark and share using ...

Delicious Facebook Digg Google Friendfeed Stumbleupon Twitter Linked In