I am playing around a bit with scripting in iChat. I want to keep things simple to start with by using the following script, set to run when a message is received:
using terms from application "iChat"
on message received TheFollowingText from theBuddy
display dialog TheFollowingText
display dialog theBuddy
end message received
end using terms from
The first part works fine, and displays the text of the message without any trouble. The second part, however, when trying to display the name of the buddy, give the following error, where “screenname” was the name of the buddy, changed for privacy!
Event: Message Received
File: Receive Message.scpt
Error: Can’t make «class pres» id “EB12E125-C62C-4683-936C-4A0CF176E34A:screenname” into type string.
I tried coercing (or so I think) theBuddy into text using
on message received TheFollowingText from (theBuddy as text)
but got an error on compiling.
Does anyone know what’s causing my error, or what I can do to achieve my desired results? I want it done so that I can filter actions based on the person who sent the message!
A buddy is an object, and as such it has properties like “id”, “status” etc. You can look at iChat’s dictionary to see more properties of a buddy object. In your case you would be interested in either the “name” or “handle” properties so you could use this. Note I haven’t tested it.
using terms from application "iChat"
on message received TheFollowingText from theBuddy
display dialog TheFollowingText
set buddyName to name of theBuddy
set buddyHandle to handle of theBuddy
display dialog "Name: " & buddyName & return & "Handle: " & buddyHandle
end message received
end using terms from
You’re welcome huskrfreak88. The only way to learn what you can do with an application is to open its dictionary and look through the commands. For example iChat. There’s a fast way to open its dictionary if both iChat and Applescript Editor are showing on the Dock. Hold down the “command” key and drag the iChat icon onto the Applescript Editor icon. When you release the icon the dictionary for iChat will open. Then in the search field of the dictionary just enter “buddy”. You can then see everything about a buddy. That’s how I found your answer. It only took a few seconds.
NOTE: use the “open dictionary” command from the file menu of Applescript Editor if you can’t do the drag-stuff I mentioned.
The same way as you’re learning a foreign language: Dictionary (described by Hank) and grammar guide (books like the guides of Matt Neuburg and Hanaan Rosenthal).
And there is another analogy with a real language: the better you speak it the more fun you have
I prefer yet another analogy.
It is a bit like learning bicycling, practice makes master. You’ll fell off a couple of times but eventually you’ll learn it as long as you are patient and don’t give up on it.