Fun with Mail, AppleScript, Python, and TaPingYa.
We use the Confluence Wiki to document development requirements and other information useful for the projects we are working on. I thought it would be cool to update my team when any of the project pages were modified. There are many ways of doing this, but I thought a learning experience using TaPingYa would be fun. What I ended up doing is using a Mac OS Mail Rule to look for emails with [wiki] in the subject line coming from the address of the Wiki emailer. The rule then executes an AppleScript that takes the email subject and makes a call to a Python script that knows how to post to TaPingYa.
The AppleScript was easy (note, I replaced login information with username, password and room_password):
(* Send message to tapingya based on mail. *) using terms from application "Mail" on perform mail action with messages selectedMessages repeat with eachMessage in selectedMessages set myString to subject of eachMessage do shell script "python ~/Documents/workspace/tahelpya/trunk/twitter/tapingya.py username password 1234 room_password \"" & myString & "\"" end repeat end perform mail action with messages end using terms from
You save compile and save this script somewhere on your computer. I chose Documents, which is the default.
Next, the Python. The Python is a bit trickier as I had to authenticate to the TaPingYa services using Basic Authentication. I created a Python class to do this work, making a nice method for posting messages to the provided room. Source code is here:
The last step was to setup the simple rule in Mail. You simply select AppleScript as the rule action, provding the path and script file created in the first step.
That was that. Now, whenever a page is modified on the wiki that I am interested in, the TaPingYa room will get a message with the subject of that email. Of course, this only works when my Mac is running and Mail is open. Quite a limitation. However, it was a fun test and a way to learn a bit of AppleScript and integration through Python to TaPingYa.
