I often exchange small snippets or links with my girlfriend, and it's been very annoying having to right click on iChat, select the correct account and start a chat. So I've automated it!
Here is a small PyObjC snippet that will allow you to send iChat messages from the command line, using the ScriptingBridge framework and a bit of elbow grease. The next step would be to make a wrapper for it so it can live a an icon on the Desktop, but I'll try that some other time.
#!/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
from ScriptingBridge import SBApplication
import sys
ichat = SBApplication.applicationWithBundleIdentifier_("com.apple.iChat")
ichat.activate()
service = 'AIM' # a part of the service name
handle = 'handle@aim.com' # the handle of the contact
buddy = [b for b in ichat.buddies() if b.handle() == handle and service in b.service().name()][0]
recipient = buddy
service = buddy.service()
chats = [c for c in service.chats() if buddy.handle() in [b.handle() for b in c.participants()]]
if chats:
chat = chats[0]
if chat.active():
recipient = chat
words = sys.argv[1:]
close = False
if words and words[-1] == 'X':
close = True
words = words[:-1]
ichat.send_to_(' '.join(words), recipient)
for window in ichat.windows():
if 'Chat with' in window.name():
window.setVisible_(not close)
Use like that:
./chat.py Hello, world!
Finishing a message with X will hide the chat window. If you know of a better way to lookup buddies than my current stupid list iterating, please share!
Interestingly, this will allow you to have conversations with yourself, if you put your own handle. Messages will be double, and some (null)s appear in the UI.
Comments
Comments are not allowed in this post

Comment by thodoris , 3 years, 2 months ago :
"this will allow you to have conversations with yourself"
...lo and behold, the future of philosophy..! :D