My wife of close to a year has a macbook that I rarely use but am increasingly intrigued by. Out of the blue I get a business trip to London for one week (we live in Chicago), where my wife's brother lives. She would love to come with me but alas her passport is in limbo. Why? She is having her last name changed to mine...DOH! Feeling bad about all of this I devise a plan to leave cards hidden around the house that contain riddles that divulge the location of a small present, one each day while I am away. The only problem - how to indicate the location of the clue cards, which are themselves hidden? I thought about email, but decided I would probably be too busy to remember every morning, and the time difference would be tricky. A phone call is no good because she would use her jedi mind control powers to bypass the clues and get straight to the present. Maybe an automated daily event of some kind...? After some thinking I come up with a simple file/shell script combination that I leave on her laptop:
The file (clues.txt) is a text file with a line for each day/clue that starts with the date followed by a colon, e.g. "Mar_19:<the riddle>".
An example riddle/clue is:
"From where I sit from daybreak to close, right under this is under my nose" (I do development work full time from home, and the card was under my keyboard)
cluekey=`date | tr -s '[:space:]' | cut -d" " -f2,3 | tr ' ' '_'`;
clue=`cat "$CLUES" | grep "$cluekey" | cut -d":" -f2`
if [ "X$clue" = "X" ]; then
echo "No clue today!";
Simple enough - now for the really cool part - the Macbook has a feature that I stumble across called "automator" which is basically a workflow engine that uses as tasks various actions from various applications on the computer. One of these actions is "Run Shell Script" - which takes text input and gives text output. Another workflow task is "Text to Speech", which takes text as input and "speaks" the text as output. I create a simple 2 step workflow of my script and the text to speech piece, and then the automator allows me to save the workflow as an application on the desktop! I save the workflow as "GetTodaysClue" and stick it right in the middle of her desktop. Before I leave to catch my flight on Friday I leave some flowers and a card that points out the curious new icon on her desktop, and the game is afoot. The clue automatically changes each day and is spoken as many time as my wife needs to hear it before the next day - brilliant!
The whole plan was a huge hit, and I gained a great deal of respect for the mac - so much so that I plan on buying one when my PC dies.