Use AppleScripts to remake the AIM buddy list

Mar 22, '05 09:03:00AM

Contributed by: robophilosopher

So I just switched from iChat to Adium the other day. I like Adium better; the problem is that I was stupid about groups on the AIM buddy list. iChat ignores groups; Adium does not. I wanted groups ignored, but didn't realize I could just drag everybody into one group in Adium. My solution was to write/modify a couple of AppleScripts: one to grab all of the AIM handles from Address Book and the other to populate the buddy list in AIM (using AOL's actual client), putting everyone in the same gruop.

Again, if you have the exact same problem I did, this is certainly not the best way to solve the problem -- but maybe the AppleScripts will help people out there who want a glance at how Address Book and AIM could be scripted usefully. The first script borrows much from a previous hint, and the second is a modification of a script that comes with AOL's AIM client.

Script 1: Get AIM handles from the Address Book and put them in a text file:

-- Config this to your liking
set saveExport to "/Users/me/Desktop/contacts.csv"

set resultText to ""

tell application "Address Book"
  repeat with x from 1 to the count of people
    set thePerson to person x
    
    if (count of AIM Handle of thePerson) > 0 then
      repeat with q from 1 to the count of AIM Handle of thePerson
        set my resultText to my resultText & ¬
         value of the AIM Handle [q] of thePerson & return
      end repeat
    end if
    
  end repeat
  my writeToFile(saveExport, saveExport as POSIX file)
end tell

-- Write a string in a file; overwites if exists
on writeToFile(theUFile, theFile)
  set touch to "touch " & theUFile
  do shell script touch
  try
    open for access file theFile with write permission
    set eof of theFile to 0
    write (my resultText) to theFile starting at eof
    close access theFile
  on error
    try
      close access theFile
    end try
  end try
end writeToFile
Script 2: Populate an AIM buddy list from a plain text file:
set myFile to (choose file with prompt "Select a file: ")
open for access myFile
set theFile to (read myFile)
close access myFile

tell application "AOL Instant Messenger (SM)"
  if online then
    
    set theGroup to group "Buddies" of buddy list
    
    repeat with theIndex from 1 to 198
      set theBuddyName to word theIndex of theFile
      set the clipboard to theBuddyName
      make new buddy of theGroup with data theBuddyName
      delay 0.5
    end repeat
    
  end if
end tell
Caveats: In the second script, each of your screen names must be one word. AIM screen names are spacing- and capitalization-independent; just remove spaces from the names. Also, if you screw around too much with your AIM buddy list, the nice people at AIM will not let you edit it for a little while, and you'll get rather cryptic errors about it for a day or so.

Hope this helps somebody.

Comments (3)


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