Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A set of scripts to translate iChat acronyms Internet
I'm not a big acronym user, finding it generally faster to type what I'm thinking than abbreviate it. However, I often find myself on the receiving end of acronyms that I have no idea what they mean. For fun, I went onto the web and scraped a few web pages listing hundreds of common chat acronyms and made a tool that I can use to very easily translate these on the fly while using iChat.

I made two scripts that work together, allowing me to highlight text in iChat and get a quick translation of any acronyms in the highlighted text. Due to the fact that the perl script was a few thousand lines with all the definitions, I've cut out all but four acronyms so that folks can add their own or contact me for the full set of definitions if they want. As the definitions were simply scraped off the web, I make no claims on the quality of the content of the translations which also contain some swear words. You might wish to create your own list of definitions and add them to the script.

I'm a self taught scripter, so I'm sure there might be shorter and or better ways to do this. It's intended to be able to translate whole sentences containing acronyms, and the way it handles deconstructing white space and punctuation and re-assembling them might be handled better, but it seems to work fine for me as is.

Some notes:
  1. The AppleScript uses UI scripting, so make sure 'Enable access for assistive devices' is checked in System Preferences -> Universal Access.

  2. Save the AppleScript and name it something like acronym_trans.scpt. Using a script launcher program such as DragThing, of course, makes this even more convenient to use.

  3. Save the perl script as im_translator_ichat.pl. Make sure that the path to this script as contained in the AppleScript matches wherever you choose to put it. Mine is ~/bin/im_translator_ichat.pl.

  4. Give the perl script execute permissions: chmod 755 im_translator_ichat.pl

  5. Expand the hashes in the define_translation_hashes subroutine to meet your needs. For each acronym you add to the %im_acronym hash, the translation must be added to the %im_translation hash and have the same key name. See the comments in the define_translation_hashes subroutine.
Now next time you get an acronym in a chat, just highlight it and run the AppleScript, and you should get an applscript dialog with he translation.

Applescript:
tell application "iChat"
  activate
end tell
tell application "System Events"
  tell process "iChat"
    keystroke "c" using {command down}
    delay 2
    set myData to (the clipboard) as text
  end tell
end tell
do shell script "perl ~/bin/im_translator_ichat.pl " & "\"" & myData & "\""
Perl:
#!/usr/bin/perl -w
use strict;

my $out = "";
my ($im_acronym, $im_translation) = &define_translation_hashes();
my %im_acronym = %{$im_acronym};
my %im_translation = %{$im_translation};

my $string = $ARGV[0];
my @string = ();


################################################

@string = &split_on_white($string);

&translate(\@string);

for(@string){
  if($_ =~ m/^[.?!,]$/m){
    $out .= "$_";
  }
  else{
        $out .= " $_";  

  }

}

my $SCRIPT =<<EOS;
tell application "iChat"
    activate
  display dialog "$out"
end tell
EOS

open (FH, "|/usr/bin/osascript");
print FH $SCRIPT;
close FH;

exit;

################################################

sub split_on_white(){
  my $string = shift @_;
  
  #all white space to single spaces
  $string =~ s![ \t]+! !mig;
  $string =~ s/([.,!?])/ $1/mig;  
  my @string = split (/ /, $string);
  
}

sub translate(){
  my $string = shift @_;
  for(@{$string}){
      my $cur_string = $_;
    
    #Check each for match to %im_acronym
    foreach my $key(sort keys %im_acronym){
      if($im_acronym{$key} =~ m#^\Q${cur_string}\E$#im){
        $_ = $im_translation{$key};
  
      }
    }      }

}

################################################

sub define_translation_hashes(){

  my %im_acronym = (
  
  im_acronym1 => "AFAIK",
  im_acronym2 => "IMHO",
  im_acronym3 => "BTW",
  im_acronym4 => "HTH",
  #ADD FURTHER ACRONYMS HERE
  
  );
  
  my %im_translation = (
  
  im_acronym1 => "as far as I know",
  im_acronym2 => "in my humble opinion",
  im_acronym3 => "by the way",
  im_acronym4 => "hope that helps",
  #ADD CORRESPONDING TRANSLATION HERE
  
  );
  
  
  my $im_translation = \%im_translation;
  my $im_acronym = \%im_acronym;
  
  return ($im_acronym, $im_translation);
}

################################################
    •    
  • Currently 3.50 / 5
  You rated: 4 / 5 (4 votes cast)
 
[8,533 views]  

A set of scripts to translate iChat acronyms | 15 comments | Create New Account
Click here to return to the 'A set of scripts to translate iChat acronyms' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A set of scripts to translate iChat acronyms
Authored by: Chris Biagini on Aug 13, '04 11:23:11AM
Hey, that's a neat idea. I hate those things. How about using something like this to simplify your Perl, though:

#!/usr/bin/perl -w
use strict;

my $string = $ARGV[0];
my @string = split (/ /, $string);

my %translate = (
    "AFAIK" => "as far as I know",
    "LOL" => "laughing out loud",    
    "BRB" => "be right back",
    );

foreach (@string) {
    if ($translate{$_}) {
        print $translate{$_};
        }
        
    else {
        print $_;
        }
    print " ";
    }
    
print "\n";
It'd be nice to add case insensitivity, too.

[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: galaher on Aug 13, '04 11:35:22AM

Since it uses a regEx match:

if($im_acronym{$key} =~ m#^\Q${cur_string}\E$#im

...the 'i' flag does make it case insensitive. So it already is. Unless you were refering to the code you suggested...



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: Chris Biagini on Aug 13, '04 11:38:02AM

I was.

Just thought that using a single hash would make additions a little easier.



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: galaher on Aug 13, '04 03:10:12PM

I initially had one hash as you suggest, but found that acronyms in my 'dictionary' often had characters that were illegal in the name of a key. e.g. im_acronym11 => "24/7", or im_acronym1 => "::POOF::". I couldn't have 24/7 => "24 hours a day, 7 days a week", so I went with two hashes. Since I scraped my acronyms off the web, it was easier to accommodate those things than try and manually clean up and edit it.



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: gancho on Aug 13, '04 10:04:06PM

Any string can be the key of a hash, including "24/7". You just need to quote the key, because smart quotes (=>) only quote what's on the left side if it's a set of word characters.



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: galaher on Sep 02, '04 04:59:48PM

I've updated the perl script to use a single hash which is much easier to update and maintain. Thanks for everyone's comments. Here's what should be a better version:



[code]
#!/usr/bin/perl -w
use strict;

my $out = "";
my ($im_acronym) = &define_translation_hashes();
my %im_acronym = %{$im_acronym};


my $string = $ARGV[0];
$string = " " . $string;
my @string = ();


#################################################################

@string = &split_on_white($string);

&translate(\@string);

for(@string){
if($_ =~ m/^[.?!,]$/m){
$out .= "$_";
}
else{

$out .= " $_";

}

}

my $SCRIPT =<<EOS;
tell application "iChat"
activate
display dialog "$out" buttons {"OK"} default button "OK"
end tell
EOS

open (FH, "|/usr/bin/osascript");
print FH $SCRIPT;
close FH;

exit;

#################################################################

sub split_on_white(){
my $string = shift @_;

#all white space to single spaces
$string =~ s![ \t\r]+! !mig;
$string =~ s/([.,!?])/ $1/mig;
my @string = split (/ /, $string);

}

sub translate(){
my $string = shift @_;
for(@{$string}){

my $cur_string = $_;

#Check each for match to %im_acronym
foreach my $key(sort keys %im_acronym){
if($key =~ m#^\Q${cur_string}\E$#im){

$_ = $im_acronym{$key};

}
}

}

}

#alt untested force upper case comparision to make case insensitive.
#print $translate{uc $_} if ($translate{uc $_};


#################################################################

sub define_translation_hashes(){

my %im_acronym = (

#BUILD YOUR DICTIONARY HERE:
"BTW" => "by the way",
"HTH" => "hope that helps",
"IMHO" => "in my humble opinion",

);

my $im_acronym = \%im_acronym;

return ($im_acronym);
}


#################################################################

__END__
[/code]



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: Chris Biagini on Aug 13, '04 11:35:36AM

I used print statements, by the way, because I tested this from the command line...I'm a little hazy on how to translate between Perl and AppleScript. :)



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: gancho on Aug 13, '04 10:07:18PM
To make your program case-insensitive, just force your key comparisons to always use uppercase or lowercase. Make all the keys uppercase, as you'e done, and then say

        print $translate{uc $_} if ($translate{uc $_};


[ Reply to This | # ]
WTF-X
Authored by: cybergoober on Aug 13, '04 11:28:02AM

There's an app called WTF-X (found on versiontracker) that has a database of acronyms that you can add to as well. This app adds a "Lookup Acronym" item in the "Services" menu as well for quick lookups.



[ Reply to This | # ]
Here's the link to WTF-X...
Authored by: 5chm31din6 on Aug 13, '04 11:50:40AM
A set of scripts to translate iChat acronyms
Authored by: GlowingApple on Aug 13, '04 04:08:30PM

I'm not too familiar with Perl, is there any way to do this entirely in Applescript? I'd like to be able to capture iChat messages in a script so I can create a sort of remote command line for my mac (since if I don't know the current IP I can still send an IM and have it return that IP). So if I could capture the last message in Applescript then I could interpret it and send back a reply in an IM.

---
Jayson

When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: burk3 on Aug 14, '04 02:20:33PM

you could probably do that with adium. Are you talking about total unix terminal access, or just some arbitrary commands that do stuff, like turn on/off itunes, run a script, etc. Either way, that would end up being very insecure, mainly because anyone would have access to it (unless you knew enough applescript to make it ask for a password, etc).



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: applecompsrule on Aug 15, '04 04:37:06PM

Actually, I'm pretty sure you could do it all in iChat. Also to overcome the security issue simply make sure that it checks that it is your screenname before it does anything. This is obvious and means that someone has to know your sn password to get any control to your comp.

---
Macs RULE, get used to it!



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: GlowingApple on Aug 18, '04 12:38:41PM

No, I can actually get terminal access through SSH once I find the IP, which I figure I can do through an e-mail reply rule. But I would still like to play around with iChat as a simple command line. I know how to send a message, but I'm not sure how to get a message. Does anyone know how to get an IM with an applescript?

---
Jayson

When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
A set of scripts to translate iChat acronyms
Authored by: iSierra on Aug 13, '05 05:51:06PM

I just found this hint and I was wondering if Tiger's Dictionary would be useful for acronyms. The answer is YES, try to look for WTF or FUBAR (this one is pretty funny).



[ Reply to This | # ]