Page 1 of 1

AppleScripting Adium's send message

Posted: Thu Mar 13, 2008 11:05 am
by Buckie
Hi guys. I hope somebody with the knowledge of AppleScript can help me out there.
The idea is simple - I need to have a script that when run would send some predefined message to one contact in my list (ICQ).
I've tried different ways to do that, and one thing I'm particularly not sure about is that whether or not one has to open a new chat window to do that (or it can be done without the window) - it shouldn't interfere with other open chat windows/tabs and ideally should close right after sending the message.
This is as far as I've got:

Code: Select all

tell application "Adium"
	activate
	tell account "123456789" to make new chat with contacts {contact "123123321"} with new chat window
	send the active chat message "Hey"
	tell the first chat window to close
end tell
The problem with this script is that when some chat has already been open it will fail to bring that window to front and as a result would send the message to any current chat window. Also it would close any first window instead of closing the correct one (and it stopped working today altogether anyway for some reason).
Any suggestions are welcome.

Re: AppleScripting Adium's send message

Posted: Thu Mar 13, 2008 3:14 pm
by mtimmsj
When you make a new chat, the chat is returned from the make command. So you could set that to a variable and use that variable to send the message and close the chat, if it's the only chat in that chat window the window will close as well:

Code: Select all

tell application "Adium"
	tell account "123456789" to set theChat to make new chat with contacts {contact "123123321"} with new chat window
	send theChat message "Hey"
	close theChat
end tell

Re: AppleScripting Adium's send message

Posted: Thu Mar 13, 2008 3:26 pm
by Buckie
Thank you so much! That worked charmingly well.

Re: AppleScripting Adium's send message

Posted: Thu Mar 13, 2008 6:34 pm
by mtimmsj
Just be sure that you always use the with new chat window option to the make command and that the contact exists otherwise all kinds of weirdness can occur. There's a trac opened for part of this but so far no one has even looked at it: http://trac.adiumx.com/ticket/8864

To make sure the contact actually exists you could use an if statement:

Code: Select all

tell application "Adium"
   tell account "123456789" 
    if exists contact "123123321" then
      set theChat to make new chat with contacts {contact "123123321"} with new chat window
      send theChat message "Hey"
      close theChat
   end if
end tell

Re: AppleScripting Adium's send message

Posted: Thu Mar 13, 2008 8:11 pm
by Buckie
Thanks, I've read about that problem.
Can I use a "contact whose name contains "123123321" construction instead of "contacts {contact "123123321"}"? If so, how?
That's what I've tried in the very beginning and it didn't work.

Re: AppleScripting Adium's send message

Posted: Thu Mar 13, 2008 8:41 pm
by mtimmsj
I think the only way that would work is if you provide the entire list of contacts to the conditional whose name contains. This will also return a list instead of a single contact object, so there is no need for {}'s. For example:

Code: Select all

tell application "Adium" to tell account "123456789"
   set theContacts to every contact whose name contains "123123321"
   set theChat to make new chat with contacts theContacts with new chat window
   send theChat message "Hey"
   close theChat
end tell

Re: AppleScripting Adium's send message

Posted: Fri Mar 14, 2008 9:10 am
by Buckie
Again, thank you mtimmsj.
My aim was to use a "calculated AppleScript" in FileMaker and it now works after I realized I had to put in the paragraph marks at the end of each line in FileMaker (simply adding a new line doesn't work and AppleScript treats everthying as a single line).
So it looks good and I have a better understanding of AppleScript now.

Re: AppleScripting Adium's send message

Posted: Mon Jun 16, 2008 5:41 pm
by MasterSwitch
hi any/everyone

does anyone know if it is possible to create a new chat in the first chat window
rather than creating in a new chat window

this is because i have tabs switched on and i dont really want more than one chat window open, i would rather just keep all of my tabs together.

it would also be good to activate a tab when a specific message comes in from a specific contact

it would also be good to just get the info of any new messages received as in an applescript run because of an event, ie, message received or new message received

anyone have any ideas ?

thanks
clive

Re: AppleScripting Adium's send message

Posted: Mon Jun 16, 2008 6:15 pm
by mtimmsj
It's behavior is inconsistent but you should be able to do this with:

Code: Select all

set theChat to make new chat with contacts {contact "123123321"} without new chat window
It pops up a window then tries to merge it with an existing window. It seems that sometimes it is successful with the merge and sometimes it is not.

Re: AppleScripting Adium's send message

Posted: Tue Jun 17, 2008 1:32 am
by MasterSwitch
mtimmsj wrote:It's behavior is inconsistent but you should be able to do this with:

Code: Select all

set theChat to make new chat with contacts {contact "123123321"} without new chat window
It pops up a window then tries to merge it with an existing window. It seems that sometimes it is successful with the merge and sometimes it is not.
hi mtimmsj

your right the behavior is inconsistent
with the code

Code: Select all

	set myContact to "someone@hotmail.com" as string
	tell account "me@hotmail.com" to set theChat to (make new chat with contacts {contact myContact})
	send theChat message "hello"
the tab is created but the script falls over and the message never gets sent. plus the tabs behave screwy until you drag the new tab about, then the tabs behave themselves.

with the code

Code: Select all

	set myContact to "myYahooFriend" as string
	tell account "myYahooIdent" to set theChat  to set theChat to (make new chat with contacts {contact myContact} without new chat window)
	send theChat message "hello"
the message is sent but for me this actually opened a new second chat window
obviously using "with" instead of using without had the same effect.

with the code

Code: Select all

	tell account "myYahooIdent" to set theChat to (make new chat with contacts {contact "myYahooFriend"} with new chat window) = false
the message is sent but for me this actually opened a new second chat window

icq was even stranger, for some reason my friend was added via my aim account not my icq account and no code worked properly.
i deleted the contact and re-added them under my icq account, this time i could create a new chat window but could not create a new tab for them.

aim seemed to behave the same way as yahoo and msn did.

maybe there isnt a way to do this! - yet

clive

Re: AppleScripting Adium's send message

Posted: Mon Jul 28, 2008 5:57 pm
by Syntonic
Anyone able to successfully open a new chat in a tab?