RSVP - Please Reply

Armin's Spot on the Web


Home

Impressum

My Code


What is a Weblog?

Pictures (.Mac)


NetNewsWire: More news, less junk. Faster

Discussion

Recent Discussion

Create New Topic


iChat Status Message Script

I think I am a little late on this party. iChat AV, aside from this video chat feature, now can be scripted with AppleScript. Obviously the most fun will be scripting the status message.

Cocoaobjects has some status message scripts, mostly with iTunes. But I would like to put some code up as well. Scripting the status message is really simply, but it is also a great opportunity to use the run and idle handlers. Copy this code into Script Editor or open in Script Editor, compile, save as "Application", select "Stay Open" and double click the resulting app.

property delayTime: 5
global oldMessage
on run
	tell application "iChat"
		set oldMessage to status message
	end tell
	cycleMessage()
	return delayTime
end run
on idle
	cycleMessage()
	return delayTime
end idle
on quit
	tell application "iChat"
		set status message to oldMessage
	end tell
	continue quit
end quit
on cycleMessage()
	tell application "Finder"
		tell application "Finder"
			set currentApp to name of first application process where frontmost is true
		end tell
		set message to "is working in: " & currentApp
		tell application "iChat"
			set status message to message
		end tell
	end tell
end cycleMessage

The first two line are interesting, I setup delayTime as a property and oldMessage as global. Why and what is the difference?

A global is a variable that is available to all parts of code. We need to access the stored value oldMessage from the run and the quit handlers, so it has to be global. As all variables globals are initialised at startup and live as long as the script is running. Properties on the other hand are saved between sessions, so changes here are automatically saved until the next time the script starts. I have not built in a way to change the delayTime but another feature of properties is that they are accessible by Apple Events from other scripts, so if I wanted to change the delay time while the script is running I would write

tell application "iChatStatusMessage"
    set delayTime to delayTime +10
end tell

to access and change the delayTime externally.

The code has four handlers: run is executed when the application is launched, it stores the old message and executes cycleMessage to change to the new message. The value that either run or idle return is the delay in seconds until the idle handler is called again.

idle is called repeatedly while the app is running, this is where we continually update the status message, calling cycleMessage.

In the quit handler we set the status message back to oldMessage and the quit the applet. Don't forget the continue quit statement. If you do the applet cannot quit normally.

Finally, cycleMessage is the place where the new status message is set. Nothing special here: we ask the Finder for the current frontmost process and return its name with some extra text. If you want to change or extend iChatStatusMessage the this is where your code goes.

More Scripts on RSVP

Discuss

Google
WWW RSVP.atsites.de

This page was last updated: Tuesday, November 18, 2003 at 12:42:59 PM
Copyright 2010 RSVP - Please Reply
Mail me @ arminbatmacdotcom
Create your own Manila site in minutes. Everyone's doing it!