9.5. iChat ControlInstant messaging, a sort of real-time email system, is one of the most popular developments of the Internet age. You can chat with your grandma in Washington D.C., your dad in Wichita, or your sister in Walla Wallaall for free. In fact, instant messaging has become so popular that Apple developed its very own chat program: iChat.
Now, iChat isn't just any chat program; it supports voice and video chats, too (assuming you have a microphone or video camera). Unfortunately, iChat's AppleScript support reaches only into the realm of text messagingyou can't automatically snap pictures with your Webcam, for example. Still, if you're an AppleScript addict, there are several opportunities to sharpen your skills on iChat's text features. For example, you can let your online buddies know you're not available when your screen saver's running, or keep your buddies entertained with an endless parade of pithy quotes. Read on for the secrets. 9.5.1. Notifying iChat when the Screensaver's OnOne of iChat's coolest features is that it lets you notify your friends as to whether you're around or not. When you're at your computer, you set your iChat status to available; when you're out, you set your status to away (and if, for some unthinkable reason, you actually disconnect from the Internet for once, you set your status to offline). Conveniently for you, AppleScript can do the same thing: tell application "iChat" set the status to available --Or you can use away, or offline end tell Of course, that's nothing really unique. To add real power, you can have your script set your status to away only if your screen saver is running.
Here's how: --Part 1: on idle --Part 2: tell application "System Events" if (the name of every process) contains "ScreenSaverEngine" then --Part 3: tell application "iChat" set the status to away end tell end if end tell --Part 4: return 10 end idle Now, before your script will run properly, you have to select File Save. For the File Format, choose Application, and turn on the Stay Open checkbox, so your script continues running in the background all the time. Save the file wherever you wantbut try to make it somewhere that's easy to access, because you can only run the script by double-clicking its icon in the Finder. Here's how the code works:
When your screen saver isn't playing, the only indication you'll have that your script is running is its icon in the Dock. Since you turned on Stay Open for the script, your code continues checking your screen saver forever (or at least until you Control-click its icon in the Dock and choose Quit from the shortcut menu). 9.5.2. Displaying a Random Status MessageIn addition to telling your buddies what your status is, you can post a special message to your buddies, using iChat's status message setting. You might post some information on how to reach you while you're away, a pithy quote, or a link to a Web site you find particularly interesting. Normally, you set your status message by clicking the small pop-up button at the top of iChat's Buddy List window (Figure 9-8). However, using AppleScript, you can set your status message automatically.
Try a script like this: tell application "iChat" set the status to away set the status message to ¬ "I don't want to talk to you right now. Go away." end tell Of course, if you run that script and don't change your status message for a while, your buddies will get both bored and annoyed at your rudeness. Nowadays, not changing your status message regularly is the equivalent of not changing your bedsheets. That's why changing the script to rotate among a few status messages is such a convenient modification. Edit the script as follows, and your witty, rotating status messages will entertain your friends even when you don't have time to: --Part 1: global messageList --Part 2: on run set messageList to {"Don't leave your seat, 'cause I'll be back soon", ¬ "Stay Tuned!", ¬ "The stuff I'm doing right now is more important than talking to you"} end run --Part 3: on idle tell application "iChat" set the status to away set the status message to (some item of messageList) end tell --Part 4: return 600 end idle Since your script uses the idle handler, you have to save it as an application, using the procedure from Section 9.5.1. Once you've done that, you can run the script by double-clicking its icon in the Finder. Here's how the parts breaks down:
If you like to keep your buddies posted on what you're doing, scripting iChat's status message is definitely the easiest way. Luckily, other people have already created some more scripts for you; the free iChat Script Collection (http://cocoaobjects.com/applescript/ics/index.php), for example, includes several scripts for posting a status message based on your currently playing iTunes track. |