iChat script

LuKreme kremels at kreme.com
Tue Sep 4 11:39:17 PDT 2007


I sometimes have trouble with iChat going offline and then refusing  
to come back online.  Since my computer is on 24x7, I want people to  
be able to send me IMs all the time, but that means making sure iChat  
is online.

I used to have a file named .ichat.sh which lived in my $HOME/bin  
folder and was activated every few minutes by cron by putting in the  
crontab:

*/7 * * * * $HOME/bin/.ichat.sh

and that file contained:

#!/bin/sh
osascript -e  'tell application "iChat" to log in '\

and was executable

Recently, I've noticed that sometimes iChat gets stuck forever in a  
"Connecting" state.  It will never connect, it will never time out,  
and it will just sit there until I manually disconnect and then  
reconnect.

So, I made the script, I thought, a tad better:

#!/bin/sh
osascript -e 'tell application "iChat"'\
           -e '  if (status is equal to connecting) or (status is  
equal to disconnected) or (status is equal to disconnecting) then'\
           -e '          log out'\
           -e '          log in'\
           -e '  end if'\
           -e 'end tell'

Trouble is, when ichat is OFFLINE, its status is 'Available'.  What  
status this is, exactly, I'm not sure.  But to get the real status,  
you have to get the status of a particular service. I ended up having  
to do this:

#!/bin/sh
osascript -e 'tell application "iChat"'\
           -e 'if status of service "AIM" is not connected then`\
           -e '          log out'\
           -e '          log in'\
           -e '  end if'\
           -e 'end tell'


which was frustrating since I had to find this on google,

Anyway, this might save someone else the trouble, and it does appear  
to work correctly as I watched the status cycle from disconnected to  
connecting to connected.

The log out/log in is important because it breaks the endless  
'Connecting..." issue, and nothing else seemed to for me.

-- 
"I do not feel obliged to believe that same God who endowed us with  
sense, reason, and intellect had intended for us to forego their  
use."  -Galileo




More information about the MacOSX-talk mailing list