Page 1 of 1

[HELP REQ] AppleScript to tell Adium to go away

Posted: Sun Dec 04, 2005 10:27 am
by MordEth
If anyone can help me with this, I'd appreciate it greatly.

I'm trying to write a script to have Adium go away if i send myself (from another screen name) a message saying "go away". (i.e. when I forget to go away before leaving my apartment.) Unfortunately, I'm not very good with Applescript, and am having trouble getting this to work.

What I have right now:

Code: Select all

tell application "Adium"
	if (get content plainText message) = "go away" then
		set my status message to "leave a message."
		set my status type to away
	end if
end tell
I have Adium calling this script on any message received from my other user, but so far i cannot get it to only work when i send "go away", and not when I send any mesage (i.e. removing the if statement works).

On a somewhat related matter...is there any way to have Adium select a pre-defined status message? Ideally, rather than picking an away status, it'd be preferred if I can tell myself which of my preset status messages to use.

One final thing, which I think may be a bug...if I remove the if statement, and manage to send myself away with that script, it looks like this:

Image

(Note that b0r3dm0ri is not being handled by Adium, so that account is not showing as away.)

Shouldn't this be changing the color of the status message (at the top of the contacts window) to red, rather than green?

Again...thanks in advance for any assistance.

Posted: Sun Dec 04, 2005 4:58 pm
by Ludge
I know Evan did a lot of work on applescript recently, but I don't think you can set your status to away properly. Have a search on Trac for applescript status and there might be a sample script or two.

Posted: Sun Dec 04, 2005 5:24 pm
by Tipo 61

RE: parsing content from a received message

Posted: Mon Dec 05, 2005 12:40 am
by MordEth
Thanks for the tips. I've looked at a lot of other people's scripts, and that's how I figured out how to send myself away.

Mostly what I'm having a problem figuring out, though, is how to get content received by Adium (a message), so that I can compare it against something ("go away") to have the Applescript do an action.

Anyone have any suggestions on this?

Thanks again for all of your assistance.

Re: RE: parsing content from a received message

Posted: Mon Dec 05, 2005 1:41 am
by evands
MordEth wrote:Mostly what I'm having a problem figuring out, though, is how to get content received by Adium (a message), so that I can compare it against something ("go away") to have the Applescript do an action
Never say never, but I'm not aware of support for having applescripts being triggered by anything incoming... Colloquy has great support for extensibility in this way via applescript; perhaps an interested party could apply code from there to Adium.

Re: RE: parsing content from a received message

Posted: Mon Dec 05, 2005 3:18 am
by MordEth
evands wrote:Never say never, but I'm not aware of support for having applescripts being triggered by anything incoming... Colloquy has great support for extensibility in this way via applescript; perhaps an interested party could apply code from there to Adium.
Hrm. I was thinking that since scripts could be triggered off of the receipt of a message by a particular user (which is what I'm doing now), it might be possible to use Applescript to get the content of that mesage from Adium. (note: I'm not all that great at Applescript, though.)

Although after reading your message, I did think of something that I could do, even if it's kind of kludge. this works reasonably well:

Code: Select all

tell application "Adium"
	set LastMessage to (do shell script "cd "/Users/mordeth/Library/Application Support/Adium 2.0/Users/Default/Logs/AIM.kuraakudeibiddo/b0r3dm0ri"; tail -n1 "`ls -x1 | tail -n1`"")
	
	if LastMessage contains "go away" then
		set my status message to "leave a message."
		set my status type to away
	end if
end tell
There's probably a better way to have Applescript read the last line of the newest file in a directory, but i know shell scripting far better than I know Applescript.

Thanks again for everyone's comments and assistance. If anyone finds a better method to do this (or pick a preset away status), let me know. ^_^