Garry Pettet
Garry Pettet

Reputation: 8288

Get contents of iChat message via Applescript

I'll preface this with the fact that I'm new to applescript...

I have iChat set up to run this script whenever a new message is received:

using terms from application "iChat"

    on message received theMessage from theBuddy for theChat

        set theHandle to handle of theBuddy

        tell application "MyApp"
            receivedInstantMessage from theHandle message theMessage
        end tell

    end message received

end using terms from

This works as expected an MyApp (which I'm coding) receives two strings (the handle of the buddy and the message content). The only trouble is that this script only seems to work once at least one message has been received in iChat. I.e the script seems to only work from the second message onwards. If the buddy logs out, he'll have to send two messages again before my app receives the AppleEvent.

Am I making a basic mistake here?

Upvotes: 1

Views: 2434

Answers (1)

Asmus
Asmus

Reputation: 5257

The first message is actually a "text invitation" so your notification script will need another handler:

on received text invitation theMessage from theBuddy for theChat
  --  your tell app statement goes here
end received text invitation

Upvotes: 0

Related Questions