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 - Ambush offline User

You really want to chat with somebody but is consistently offline, away or idle. He seems to go online occasionally, but of course, you have better things to do than watch the Buddy List all the time. So let your computer do the watching.

Copy and paste the following code into Script Editor or open in Script Editor, save the script as application and be sure click on "Stay open" before saving. You can place the Scriptlet in the "Scripts" folder for easy access from iChat.

property watchedUser : ""
property message : ""
property idleTime : 15
on run
	set watchedUser to first item of chooseChatUser()
	tell me to activate -- bring to front
	display dialog "Ambush '" & watchedUser & "' with message:" default answer "Hi there!"
	set message to text returned of result
	tell application "iChat" to activate -- bring to front
	return idleTime
end run
on idle
	if watchedUser is not "" and message is not "" then
		tell application "iChat"
			set theList to id of every account where status is available
		end tell
		if theList contains watchedUser then
			sendChatMessageToUser(watchedUser)
			quit
		end if
	end if
	return idleTime
end idle
on quit
	set watchedUser to ""
	set message to ""
	continue quit
end quit
on chooseChatUser()
	tell application "iChat"
		set theList to id of every account where status is not available
		return choose from list theList without multiple selections allowed
	end tell
end chooseChatUser
on sendChatMessageToUser(userID)
	tell application "iChat"
		-- strange workaround because iChat AV Beta returns strange things
		repeat with a in (every account where id is userID)
			send message to a
		end repeat
	end tell
end sendChatMessageToUser

This script follows the basic structure any script that idles in background to watch something should follow. The run handler sets up the required data. The idle handler checks if anything changed and performs the necessary actions if the criteria are met (i.e. the user has finally come online. Finally the quit handler cleans up.

The scriptlet icon will appear in the dock and if you want to cancel the 'ambush' then simply quit the script from the dock or by acticvating it and selecting 'quit' fom the menu.

This script only watches for a single user. If you would like to handle several messages waiting for several users, the UI would get a lot more complicated and you would have to change the script to a AppleScript Studio project.

There is bug in iChat AV beta that makes the strange construct used in sendChatMessageToUser() necessary. If the final version fixes that, you could just use send message to first account where id is watchedUser. We'll see.

More Scripts on RSVP

Discuss

Google
WWW RSVP.atsites.de

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