Here is an AppleScript you can easily use (on 10.9) to login/log off in Messages freom all ersvices. You can modify it to be service specific and can cather the specific service state by appending the corresponding number of the service (it’s numbered like one would count).
I personally use it in conjunction with Alfredapp so I just enter “IM” and it will automatically change my online-status to offline or vice-versa. Much fun. Feel free to use, share and do whatever you want to do with it.
tell application “Messages”
set aServiceState to status
set anApplication to application “Messages”
if aServiceState is available then
tell anApplication to log out
if aServiceState is offline then
tell anApplication to log in
Edit 01.01.2014: Have a look at the comments section. Megadroid posted an improved version.