AdiumX Console Trash

I’m very sick of the INFO cmdproc.c:98:show_debug_cmd() rubbish that the latest Adium release is spewing into my Console Log twice a minute.

I’m finding I’d rather leave IM off, than see it traced across my desktop.

(I use MkConsole to keep an eye on things).

Update: it looks like 1.3.2b1 fixes this. Yay!

Hosted Gmail and Gtalk

There exists a small bug in Adium, which apparently has been fixed in an upcoming version, which means that hosted Gmail accounts cannot sign in as GTalk accounts. To fix it, I needed to create a new Jabber account, with the following settings: Account. Jabber ID: matt@schinckel.net Password: •••••••••••••••• Options. Connect Server: talk.google.com Resource: Adium Port: 5223 ☑ Force old-style SSL Then it connected fine, first time.

Reconnect all Adium Accounts.

Just a little quickie: sometimes Adium loses connections. This script will reconnect any disconnected accounts.

1
2
3
4
5
    tell application "Adium"
        repeat with acc in accounts
            connect acc
        end repeat
    end tell

Using /commands in Adium

I had a thought as to why it might not be a good idea to use /commands, instead of %_commands in Adium. If the text you type is part of a URL, then it will be replaced by the substituted text. For instance, http://itunes.schinckel.net/ would be replaced by http:/♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path.schinckel.net/, which is probably not desired behaviour. I’m not sure if this is a big enough deal for me to stop using them. I did also note that an afp:// had a smiley inserted into it instead… Update: You can add the following to the Info.plist:

1
2
                <key>Prefix Only</key>
                <true/>

Where the keyword appears. This will mean that the tag must be at the start of a ‘word’ for it work. Thanks, Reikon!

Adium Multi Chat

I had to fix a couple of things in my Adium Scripts tonight: I figured out that if you are a chat with more than one person (like in a Jabber ‘room’), and you use serviceClass of contact of the active chat of the first interface controller you will get a list of items, not just one. Actually, you always get a list, just usually it’s only one item long. So, to test if the chat serviceClass is in a set that can handle HTML in chats, you need to use first item of serviceClass... instead of just serviceClass... Note that this returns correct values, wheras serviceClass of chat 1 (where it is a group chat) will return an empty string. Bad coding, Adium. Anyway, I’ve fixed /who to work with multi-person chats, too.

Phase One of iTunes Chat Client

I’ve started phase one of the iTunes controller bot: I’m downloading the jabber server for MacOS X. $ sudo port install jabberd Phase Two will soon be underway: I’ve also downloaded the source of a Python bot… more to come soon! Actually, getting the jabber server to work wasn’t as easy as it should have been: I’m using a private jabber account on a server only I know about, but I’ll post more stuff as I get it working. Python looks to be an easy way of getting the bot to work: it would be nice to be able to do it all in AppleScript though. I can’t believe I just said that!

Who Else Am I Chatting To?

Not that this has ever come up, but there is an AppleScript out there somewhere that allows you to type %_who into Adium, and it returns a list of people you are chatting to.

Naturally, it was sub-standard, and I have improved it.

Features mine has:

  • Don’t display the name of the person who you say this to
  • Display “I’m not chatting to anyone else.” if you aren’t
  • If the person you are chatting to can handle HTML in chat (Jabber, AIM), then list display names of the people you are chatting to, with each person a clickable link that will open a chat with that person
  • Otherwise, display a list of people you are chatting to, with the type of chat listed after each name

I’ve included the old one if anyone was interested: you can get it by typing %_who. Mine uses /who, and you can download it from Adium Xtras.

Chatting to Robots?

I had a thought just before. (Unusual, I know). I wrote a program called iTunesRater so I can rate my music as I listen to it in iTunes, and then went on to write a series of Adium Scripts to control iTunes ratings, and get data from iTunes.

What if instead of having to create scripts for iTunes that did everything you want, you just create a bot that runs, and you send messages to it, and it controls iTunes. So, I could have the program running, and instead of having to type: /itunes

_♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path _

/rate{44} /itunes

♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path ★★

I could just start up a chat with iTunes, and type all sorts of commands:

me: song

it: ♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path

me: rate 44

it: ♫ The Chemical Brothers (Feat. The Flaming Lips) • The Golden Path ★★

me: next track

[iTunes next track plays]

All it would seem to require is a program that can connect to a server of some sort (I think maybe Jabber, then I can run my own Jabber server!), and sends AppleScript messages to iTunes. Or any other application, for that matter.

Even better Current iTunes Track

It’s nice to show other users what you are listening to, and provide a handy link for them to see more about the artist and track. I noticed that some IM systems don’t like HTML, and I figured out a way to make the link only be sent to a user of an AIM compatible or Jabber server.

Basically, you test the result of serviceClass of contact of the active chat of the first interface controller, and if it is “AIM-compatible” or “Jabber”, then you use HTML, if not, just plain text. You can download it from Adium Xtras: Now Playing in iTunes.

Full Source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
– Better itunes adium link script
– Includes rating (if present), and links.
property message_prefix : «data utxt266B0020» as Unicode text
property not_listening_message : "Quiet"
property star : «data utxt2605» as Unicode text
property google : "http://www.google.com/search?q="
property server : ""

property html_classes : {"AIM-compatible", "Jabber"}

on substitute()
    –set server to "http://" & my getIP() & ":8080" — Use betterGetIP if on broadband!
    
    tell application "System Events"
        try
            get process "iTunes"
        on error
            return message_prefix & not_listening_message
        end try
    end tell
    
    tell application "iTunes"
        if player state is not playing then
            return message_prefix & not_listening_message
        end if
        set theArtist to artist of current track
        if theArtist is "" then set theArtist to "Unknown Artist"
        set theTrack to name of current track
        set theRating to " " & my myRating(rating of current track)
        set theLocation to location of current track
        set pth to my encode_URL_string(characters 9 thru end of (POSIX path of theLocation) as string)
    end tell
    
    tell application "Adium" to set accountType to serviceClass of contact of the active chat of the first interface controller
    if first item of accountType is in html_classes then
        return html(message_prefix & my myLink(google, theArtist) & " • " & my myLink(server & pth, theTrack) & theRating)
    else
        return message_prefix & theArtist & " • " & theTrack & theRating
    end if
end substitute

on myRating(theRating)
    set theResult to ""
    set theTimes to (theRating - 9) / 20 as integer
    repeat theTimes times
        set theResult to theResult & star
    end repeat
    return theResult
end myRating

on myLink(URI, theText)
    if URI is google then
        set URI to URI & first word of theText
        repeat with wd in (rest of every word of theText)
            set URI to URI & "+" & wd
        end repeat
    else if server is "" then
        return theText
    end if
    return "<a href=\"" & URI & "\">" & theText & "</a>"
end myLink

on html(str)
    return ("<HTML>" as Unicode text) & str & "</HTML>"
end html

on getIP()
    return do shell script "ifconfig ppp0 | grep inet | awk ‘{print $2}’"
end getIP

on betterGetIP()
    return do shell script "curl -s http://www.showmyip.com/simple/ | grep GMT | awk ‘{print $1}’"
end betterGetIP

property allowed_URL_chars : (characters of "/$-_.+!*’(),1234567890abcdefghijklmnopqrstuvwxyz")
property hex_list : (characters of "0123456789ABCDEF")

on encode_URL_string(this_item)
    set character_list to (characters of this_item)
    repeat with i from 1 to number of items in character_list
        set this_char to item i of character_list
        if this_char is not in allowed_URL_chars then set item i of character_list to my encode_URL_char(this_char)
    end repeat
    return character_list as string
end encode_URL_string

on encode_URL_char(this_char)
    set ASCII_num to (ASCII number this_char)
    return ("%" & (item ((ASCII_num div 16) + 1) of hex_list) & (item ((ASCII_num mod 16) + 1) of hex_list)) as string
end encode_URL_char

on run
    tell application "Adium" to activate
    my substitute()
end run

Getting the Active Chat in Adium

Getting the active chat in Adium from AppleScript appears at first look to be a little dicey: Adium needs to actually be the active application before the code actually works! For instance, if you open up the Script Editor, and type in the following:

tell application “Adium”     get contact of the active chat of the first interface controller end tell

You will get an empty list: {} To get a result, all you need to include is:

    activate

just before you access something belonging to the active chat. If you are creating an AdiumScript, and are testing it in the Script Editor, chances are you have used the idiom:

on run     my substitute() end run

To get this to work if you are using the active chat, it just needs to be changed to:

on run     tell application “Adium” to activate     my substitute() end run

Happy AdiumScripting!