Rtf Hyperlink Tags

HI,
I received a SImple text RTF file formatted as a table with a few hundred lines

each line contains some infos and the last is a “mailto” tag which only appears as a blue underlined text (example: London) hidding the actual url.

I tried to save it as a simple text file but I loose the url address

Ids there a way to convert the table in a text file where the various fields separate with tabs and the last field gives the full url address instead of the hyperlink|? (EXAMPLE:

MODERN Art [tab] Fotography [tab] Black and white [tab] competition [tab] www.thesite.fr

I am really a new user of applescript and I only found software converting everything to html which is no use to me since the file is long and editing the html source is really time consuming

Thanks a lot

I

Hi,

try this, it creates a plain text file in the same folder with .txt extension


set theFile to choose file of type "public.rtf" without invisibles
tell application "Finder" to set parentFolder to container of theFile as text
set theSource to paragraphs of (do shell script "cat " & quoted form of POSIX path of theFile & " | awk /cell[^a-z]/")
set theResult to {}
set theLine to {}
repeat with oneLine in theSource
	if oneLine ends with "\\cell " then
		set end of theLine to extractValue(oneLine)
	else if oneLine contains "HYPERLINK" then
		set end of theLine to extractHyperlink(oneLine)
	end if
	if oneLine ends with "\\row" then
		set {TID, text item delimiters} to {text item delimiters, tab}
		set end of theResult to theLine as text
		set text item delimiters to TID
		set theLine to {}
	end if
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set theResult to theResult as text
set text item delimiters to TID

set {name:Nm} to (info for theFile)
set destinationFile to parentFolder & Nm & ".txt"
try
	set ff to open for access file destinationFile with write permission
	set eof ff to 0
	write theResult to ff
	close access ff
on error
	try
		close access file theFile
	end try
end try


on extractValue(t)
	set {TID, text item delimiters} to {text item delimiters, "\\"}
	set t to text item 2 of t
	set text item delimiters to space
	set t to (text items 2 thru -1) of t as text
	set text item delimiters to TID
	return t
end extractValue

on extractHyperlink(t)
	set {TID, text item delimiters} to {text item delimiters, "HYPERLINK"}
	set t to text item 2 of t
	set text item delimiters to quote
	set t to text item 2 of t
	set text item delimiters to TID
	return t
end extractHyperlink


Thanks I’ve tried the script but I receive this error constantly:

Result:
error “Can’t make text items 2 thru -1 of "f0" into type text.” number -1700 from text items 2 thru -1 of “f0” to text

and the script end …

any additional suggestions?

Thanks

I’ve tested the script with a RTF document containing only the table.
Maybe your document contains other elements which are caught by the awk command.

Parsing RTF documents is as weird as GUI scripting :wink: