using terms from application "Mail" property viewer_cols : {from column, mailbox column, subject column} end using terms from property start_key : "F1" property letter_str : "" property time_out : false property time_to_quit : 2 on run tell application "Mail" tell front message viewer if exists (some message) then --just in case the mailbox is empty tell me set time_out to false repeat until time_out set pressed_keys to false set start_time to current date repeat until pressed_keys or time_out set thekey to keys pressed set pressed_keys to (length of thekey = 1) as boolean set time_out to ((current date) - start_time > time_to_quit) as boolean end repeat if not (thekey as string = start_key) then if not time_out then set letter_str to letter_str & (thekey as string) tell application "Mail" tell front message viewer if viewer_cols contains sort column then copy visible messages to thedata if not sorted ascending then set thedata to reverse of thedata end if repeat until (length of thedata) = 1 --find first message whose first letter is letter key or greater set itemCount to (((length of thedata) + 1) div 2) set aItem to item itemCount of thedata if sort column = from column then --we are searching on who its from set thesender to {} set AppleScript's text item delimiters to space set thetext to text items of (sender of aItem as string) repeat with aText in thetext if (aText) does not contain "@" then set thesender to thesender & aText end if end repeat set thesender to words of (thesender as string) as string set AppleScript's text item delimiters to "" set which_way to (thesender > letter_str) as boolean end if if sort column = mailbox column then --we are searching on which mailbox its in set boxname to name of mailbox of aItem set which_way to (boxname > letter_str) as boolean end if if sort column = subject column then --we are searching on what its about set thesubject to my trim_line(subject of aItem as string) set which_way to (thesubject > letter_str) as boolean end if if which_way then set thedata to items 1 thru itemCount of thedata --get reference to message else set thedata to items (itemCount + 1) thru -1 of thedata --get reference to message end if end repeat set selected messages to thedata --highlight message end if end tell end tell end if end if end repeat end tell else display dialog "Error: no messages in viewer" with icon stop end if end tell end tell end run on trim_line(this_text) set x to the length of "Re: " repeat while this_text begins with "Re: " try set this_text to characters (x + 1) thru -1 of this_text as string on error return "" end try end repeat return this_text