Archive for May, 2009

Control Adium from the Terminal

by Matt Danger on May.27, 2009, under Uncategorized

I heart Adium with its beautiful interface, extensive plugins, and scriptability. I use the app so much that I often forget to sign out when I leave home or work. This creates OTR private key conflicts when someone messages me. AIM (and maybe the other networks) will alert you if you’re signed on from multiple locations and will even let you kill the other sessions. I want to be able to remotely sign on and off from Adium and also want the ability to remotely change my account status message.

Fortunately, Adium has good Applescript support that can be extended via a shell script. I wrote this bash script that does exactly that. It is command line driven so I can SSH into my home or work computer and execute it.

#!/bin/sh
 
# Copyright Matt West  5/23/2009
 
#
# Usage
#
usage() {
    echo "Usage $0  [command]
 
Options
    -a account
        Account screen name
    -l
        Display the current account status and away message
    -m message
        Set account as away with a message
    -t type
        Status type: available, away, invisible, offline
"
    exit 0
}
 
#
# Grab our environment
#
. /etc/profile
 
#
# Define
#
APP="Adium"
 
#
# Get opts
#
while getopts "a:lm:t:" OPTIONS; do
  case $OPTIONS in
    a)  ACCOUNT=$OPTARG
        ID=`osascript -e 'tell application "'$APP'" to get id of accounts whose name is "'$ACCOUNT'"'`
        ;;
 
    l)  # Display the current account status
        STATUS=`osascript -e 'tell application "'$APP'" to get status type of account '$ID`
        MESSAGE=`osascript -e 'tell application "'$APP'" to get status message of account '$ID`
 
        if [[ $STATUS == 'away' ]]; then
            echo $ACCOUNT is currently away with the message \"$MESSAGE\" #"
        else
            echo $ACCOUNT is currently $STATUS
        fi
        exit 0
        ;;
 
    m)  MESSAGE=$OPTARG;;
 
    t)  STATUS=$OPTARG;;
  esac
done
 
# An account is required
if [[ -z $ACCOUNT ]]; then
    usage
else
    if [[ -z $ID ]]; then
        echo "Error: Couldn't find the account $ACCOUNT"
        exit 1
    fi
fi
 
# Set the status type
if [[ -n $STATUS ]]; then
    osascript -e 'tell application "'$APP'" to set status type of account '$ID' to '$STATUS
fi
 
# Update the away message
if [[ -n $MESSAGE ]]; then
    osascript -e 'tell application "'$APP'" to set status type of account '$ID' to away'
    osascript -e 'tell application "'$APP'" to set status message of account '$ID' to "'"$MESSAGE"'"'
fi

To use, copy and paste this code into an empty text file and name it adiumcontrol (or whatever you’d like). Then make the file executable:

chmod +x adiumcontrol

Then try it out. You control each IM account independently. In this example ‘habitcky’ is my AIM screen name:

./adiumcontrol -a habitcky -l
habitcky is currently available

Set your away message:

./adiumcontrol -a habitcky -m "I am currently unavailable"

Sign yourself offline:

./adiumcontrol -a habitcky -t offline

Sign yourself back online:

./adiumcontrol -a habitcky -t available

2 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Send me a message on AIM!

Friends

Read what I read...