Shut up Alex

Since getting the macbook I’ve been using iChat as my jabber client. It works fine. I’ve also turned on text-to-speech using the Alex voice for when new messages come in to a chatroom. I find I can then ‘listen in’ on chatroom discussions without having to have the chat window visible anywere. And the ‘Alex’ voice is such a major improvement over most computerised voices … that it doesn’t end up irritating me (however, it would be nice if Leopard came with a female equiv. of Alex, or some non-American accents).

Anyway, having ‘Alex’ chattering away is fine most of the time, but whenever someone posts a URL into a chatroom it becomes very irritating when Alex decides to spell out the whole thing. For example;

aytch tee tee pee colon slash slash double-u double-u double-u dot kay eee arr en eee ell see arr ay es aytch dot see oohh emm …..

Of course you can mute your overall sound quite quickly … but ultimately you just want to temporarily mute the speech volume only. Of course, inside the preferences for iChat, under Alerts is the ‘Speech Volume’ slider. Just slide that to zero and the speech goes away. Of course, that takes a bit of point and clicking … and usually I can’t be bothered.

So I thought Applescript might be the solution. I’d never looked at Applescript before, so there was a bit to learn.

Ultimately I came up with this script;

set front_app to (path to frontmost application as Unicode text)
tell application "iChat"
   activate
end tell
tell application "System Events"
   tell process "iChat"
      keystroke "," using {command down}
      click button "Alerts" of tool bar 1 of window 1
      tell slider 1 of group 1 of group 1 of group 1 of window 1 to set value to 0
      keystroke "w" using {command down}

   end tell
end tell
tell application front_app
	activate
end tell

This works with Leopard at the moment. The key line is the ‘tell slider…’ line that sets the value to zero. If you want to change the volume back to something more normal, you just use a decimal number less than 1.0. For example;

tell slider 1 of group 1 of group 1 of group 1 of window 1 to set value to 0.6

which sets the speech volume to 60%

So I’ve just saved two scripts to ~/Library/Scripts;

SpeechVolume60.scpt
SpeechVolume0.scpt

One sets the volume to 60%, the other to 0%. Then I just have some hotkeys set up in Fastscripts to call them. So as soon as I hear Alex starting to pronounced his http’s, I just hit the hotkey to shut him up. Then set the volume back to 60%.

Note: For reference I found the UIElementInspector particularly useful in working all this out.