Set location and iChat screen name via AppleScript

May 13, '04 10:32:30AM

Contributed by: dougied76

This really isn't any more than some combinations of hints. It allows one to select a network location. Based on that selection, it sets the network location and then sets an iChat screen name the user wants to use that location. That is, if one selects "work," the script sets the location to "work" and then sets the screen name to your predefined "work" screen name. At the end of the script, I have it launch iChat and Mail and then hide them both. To use this script, one must have the following set up:

  1. their location names have no spaces in them.
  2. Location#x (where x is 1, 2, or 3) is changed to the location name for location #x
  3. screennamex (where x is 1, 2, or 3) is changed to the screen name they want to use at location #x
Read the rest of the hint for the script...

Enter this in Script Editor:

-- user must edit this...any number of locations is possible
-- locations MUST correspond with screennames

set myLocations to {"Location#1", "Location#2", "Location#3"}
set myScreennames to {"screenname1", "screenname2", "screenname3"}

tell application "Finder"
 set loc to (choose from list myLocations with prompt ¬
  "Select your location:" without multiple selections allowed) as string
 if loc is "false" then return
 
 repeat with i from 1 to (count of myLocations)
  if loc is item i of myLocations then
   set nom to quoted form of (item i of myScreennames)
   exit repeat
  end if
 end repeat
end tell

try
 -- note that there MUST be a carriage return 
 -- BEFORE the "defaults" line
 (do shell script ¬
  "scselect " & loc & "
defaults write com.apple.iChat.AIM LoginAs " & nom)
 
 tell application "iChat"
  launch
 end tell
 tell application "Mail"
  launch
 end tell
 
 tell application "System Events"
  if exists application process "iChat" then
   set visible of application process "iChat" to false
  end if
  if exists application process "Mail" then
   set visible of application process "Mail" to false
  end if
 end tell
 
end try
[robg adds: I haven't tested this one myself, but an AppleScript guru friend of mine did -- he tweaked a couple of things, and pronounced it functional.]

Comments (1)


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