Recently I was fuming on Twitter about the inability to set “private times” in chat applications. I’ve spread my instant-messaging address far and wide, and that’s fine—but there are certain times (like when I’m home looking up a hey-it’s-that-guy on IMDB) when I don’t really want to begin a random chat with someone who I’ve met once and who just wants to aimlessly chat about what’s going on in the world of Macs.
The good news is, instant-message services such as AIM allow you to adjust your privacy settings, so that only people on your buddy list can see you. The bad news is, I’ve yet to find an IM program that lets you adjust those settings on a schedule. I’d love to be able to say, “accept any chat on Monday through Friday, 10 to 6, but all other times limit the chats to those people on my Buddy List.”
But it can’t be done, so far as I can tell. My next step was to dig through the AppleScript dictionary and preferences file of my current IM client, Adium. No dice.
So I entered the horrifying world of Apple’s GUI Scripting, which lets you select menus and press buttons via an AppleScript, even when the commands aren’t actually scriptable.
Below you'll find the script (incorporating the do_menu subroutine from Apple's GUI Scripting page) that turns my Adium privacy on. To turn it off, I just made a copy of this script and changed the
click menu item line to
click menu item "Allow anyone".
Use the script scheduler of your choice to set these scripts to run regularly. I used CronniX (a front-end to
cron) to run the adium-privacy-on script every hour on the weekend and during the evenings, and adium-privacy-off every hour during my work week.
It’s not an ideal solution, but it seems to be getting me what I want—which is interaction with anyone while I'm at my desk, but a whole lot more privacy when I’m at home.
Presented herewith, for those who would wish for such a thing, my Adium X script:
do_menu("Adium", "Adium", "Privacy Settings...") tell application "System Events" tell process "Adium" tell window "Privacy Settings" click pop up button 2 tell menu of pop up button 2 click menu item "Allow only contacts on my contact list" end tell click button 1 end tell end tell end tell on do_menu(app_name, menu_name, menu_item) try --bring the target application to the front tell application app_name activate end tell tell application "System Events" tell process app_name tell menu bar 1 tell menu bar item menu_name tell menu menu_name click menu item menu_item end tell end tell end tell end tell end tell return true on error error_message return false end try end do_menu