Here's how I handle this:
* I have a script that is triggered by a "Message Recieved (Initial)" event. So it will only run when someone sends me a message for the first time. This is configured in the "events" portion of Adium preferences.
* The script grabs all the dates opened values for all of the chats, saves them to a list and then sorts them saving the results to a different list. This puts the most recent date opened to the end of the sorted list.
* The script then finds the position of that date opened value in the original list. This position (just an index, i.e. a number) can be used to grab the chat you want.
Sample code (the simple_sort and list_position handlers came from Apple's Applescript website):
Code: Select all
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item is less than low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if (item i of this_list as string) is (this_item as string) then return i
end repeat
return 0
end list_position
try
tell application "Adium"
set theDates to the date opened of every chat
-- Now figure out which chat is the most recent
-- Sort the date to get the most recent one at the last place of the list
set theSortedDates to me's simple_sort(theDates)
-- Find the location in the original list the last item of the sorted list is at
set myItem to me's list_position((the last item of theSortedDates), theDates)
-- So no myItem is an index into the chats for the chat that is the one we want
set theChat to the chat myItem
-- And theChat now contains the most recent chat that was opened
end tell
on error
-- print debug message here
end try