TextEdit to Applerscript

I received a file with several html addresses coded as “Links” in an RTF document.
However in the Text edit File I can only see the link name not the actual address

Example:

Student Class (tab) Student Code (tab) Semester (tab) Email (this last words hides the student email)

I need to convert the Email link to standard text so I can import it into Filemaker

I can do this by hand using Text Edit Keystrokes:

I copy the Email word

click cmd (F)
Click Find in the Find window
Find the first occurrence in the document
Press cmd (K)
A window pops out with the actual content of the link
Press cmd (A) to select the whole content
Press cmd (C)
copy the link
Press esc or the button cancel in the window
Back now to the document
Press cmd (V)
the first occurrence of the link “email” becomes “mailto: student@class.com
Press cmd (F)

to start the process again

I used parts of several scripts I found however I am not skilled enough to make it work for me as I am unable to find the way to close the EditLink window and get back to my document.

activate application “TextEdit”
tell application “System Events”
tell process “TextEdit”
keystroke “f” using {command down}
end tell
end tell
tell application “System Events”
tell process “textedit”
keystroke “email”
end tell
tell process “TextEdit”
tell window “Find”
tell window “Find”
keystroke “w” using {command down}
end tell
end tell
end tell
tell process “textedit”
keystroke “k” using {command down}
keystroke “a” using {command down}
keystroke “c” using {command down}
end tell

(* 

NOTE
Until this point everything works fine
However I am unable to close the Edit link
I’ve tried several options but I always get an error from Applescript

System Events got an error: Can’t get process “textedit”.

The rest does not work although the content of the AEdit window is in the clipboard
*)

tell process "TextEdit"
	tell window "Edit Link"
		click button "Ok"
	end tell
end tell
tell process "textedit"
	keystroke "v" using {command down}
end tell

end tell

I am unable to find a way to close it and paste it

Can anyone help me to automate this lengthy and boring manual process?

Thanks

Hi,

the best solution is to parse the RTF text, which is actually plain text with formatting information