Scripting a Keepalive for Adium

By Paul Heinlein | Apr 4, 2016

Our team at work uses a group chatroom on a daily basis, though sometimes an hour or more will pass between flurries of messages. The chats are hosted on the enterprise-level Skype for Business Server.

During those lulls, and without warning, my Mac instant-message application Adium will silently timeout. One minute I’m connected, the next I’m not—but Adium offers no indication whatsoever of the change.

Once Adium is disconnected, I get no further messages even during the next message flurry. I’d say that ignorance is bliss, but I depend on that chatroom for information. Plus, my colleagues have a reasonable expectation that I’ll respond to their questions in a timely manner.

My temporary fix is a scripted keepalive.

SIP plugin

It’s worth noting up-front that Adium doesn’t have native support for the SIP/SIMPLE message protocol used by Skype for Business. That functionality is added by way of a plugin.

I have searched to no avail for a timeout setting I can tweak in Adium or the SIPE plugin.

Without such a knob to tweak, I resorted a workaround.

Rinse, lather, repeat

I had never done any work with AppleScript prior to this little project, and AppleScript experts may be justified in saying that I should have continued that tradition, but it was the quickest way I could devise to automate work on a Mac within a running application.

My normal workflow is to launch Adium, go online, and contact the “ourworkgroup” group chat. The Adium window hosting the chat takes on the group’s name, so the pane is titled “ourworkgroup.” The script relies on that convention; it sends the keepalive message to a chat by that name. Once I’m connected to the chatroom, I execute the AppleScript:

	set rightNow to time string of (current date)
	set myStatus to "Alive as of " & rightNow
	tell application "Adium"
		send chat "ourworkgroup" message myStatus
	end tell
	delay 1800
end repeat

You may note that the script is effectively an infinite loop. I briefly considered telling it to exit after, say, 20 iterations (10 hours), but for now I just stop and start it manually in the Script Editor application.

When launched, the script sends a message like “Alive as of 2:18:24 PM” to the ourworkgroup chat. It waits 30 minutes and then sends another (with an updated timestamp).

As long as the script is running, my chat sessions haven’t disconnected. My colleagues aren’t exactly enamoured with my little “Alive…” messages, but they were even less enthusiastic when it appeared I was ignoring them. So the lesser of two ungoods wins the day.