Watch or listen to your remote Mac with iChat AV

Oct 09, '03 10:33:00AM

Contributed by: mithras

I recently found out about iCAR, which is an open-source project to add auto-reply abilities to iChat. You can use this to do any number of things -- respond with a static 'away' message, make a 'chatbot' that talks like Eliza the therapist, or control iTunes, an EyeTV, X10 devices if you have those.

I realized that I could use this to create an instant audio or video "room monitor," allowing me to quickly check on things at home. iCAR can't yet auto-accept your invitation to an AV chat, so instead, we'll have the listening Mac invite you to an AV chat when you ask it to.

To do this, you'll need:
  1. Two Macs, both running iChat AV. I'll call one the 'listening Mac', and the other 'your Mac.'
  2. One AIM/.Mac account for yourself, and a different one for the listening Mac. You can grab one at http://aim.com.
  3. The listening Mac can use its built-in microphone, or a microphone, webcam, or Firewire digicam.
[robg adds: I haven't tested this one out yet, but I intend to -- it seems very very useful!]

To make your 'iChat room monitor,' do this:

  1. Download iCAR on the listening Mac.
  2. Download this Perl script, or copy-and-paste from the end of this hint. Remember you need to make the script executable (chmod a+x /path/to/iChatGreet.pl) if you copy-paste.
  3. In iChat on the listening computer, add yourself to the buddy list. The script will only initiate an AV chat with someone on the listening computer's buddy list.
  4. Open iChat preferences, and under 'Auto-Reply', select the script as a Unix command source.
When you want to watch or listen to the listening Mac, just start a regular text chat with your listening Mac. If you type 'listen', it will invite you to an audio chat; if you type 'watch', it will invite you to a video chat.

That's it! The script is just a stub -- feel free to post other ideas in the comments.

Script:

#!/usr/bin/perl

###############################################
#              Settings

###############################################
#               Setup
$screen_name = $ENV{'iCAR_screenname'};
$real_name = $ENV{'iCAR_name'};
$received_message = $ENV{'iCAR_message'};

$time_of_day = get_time_of_day();

## debugging:
#$screen_name = "myhandle";
#$received_message = "listen";

###############################################
#              Main response                       
if ($received_message =~ /listen/)
{
 start_media_chat($screen_name,"audio");
}
elsif ($received_message =~ /watch/)
{
   start_media_chat($screen_name,"video");
}
else 
{
      # joe public
  print "Good $time_of_day, $real_name.";
}
exit;

###############################################
#                 subroutines                       

sub start_media_chat($$)
{
  my ($screen_name_to_invite,$media_type) = @_;
  print "Starting $media_type chat...\r\n";
  close STDOUT;
  my $script = media_chat_script($screen_name_to_invite,$media_type);
  system("osascript -e '" . $script . "' &"); 
}

sub media_chat_script($$)
{
  my ($screen_name_to_invite,$media_type) = @_;
  return <<EOS;
  tell application "iChat"
    repeat with a in (every account where handle is "$screen_name_to_invite")
      send $media_type invitation to a
    end repeat
  end tell
  EOS
}

sub get_time_of_day()
{
  my ($sec,$min,$hour) = localtime(time);
  if ($hour < 12) 
  {
    return 'morning';
  } 
  elsif ($hour < 6) 
  {
    return 'afternoon';
  } 
  else 
  {
    return 'evening';
  }
}

Comments (22)


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