Copy from text edit

Hi All

Feeling Kinda stupid now as I keep having to pester u guys with questions,
I’m sure this is easy but I can’t get my head round it,
I want to copy part of a text edit file and then paste that into a new
text edit file and save it down to the desktop.

this is a portion of the text edit file

     <xapTPg:Fonts>
        <rdf:Bag>
           <rdf:li rdf:parseType="Resource">
              <stFnt:fontName>Times-Roman</stFnt:fontName>
              <stFnt:fontFamily>Times</stFnt:fontFamily>
              <stFnt:fontFace>Regular</stFnt:fontFace>
              <stFnt:fontType>TrueType</stFnt:fontType>
              <stFnt:versionString>5.0d10e1</stFnt:versionString>
              <stFnt:composite>False</stFnt:composite>
              <stFnt:fontFileName>Times.dfont</stFnt:fontFileName>
           </rdf:li>
           <rdf:li rdf:parseType="Resource">
              <stFnt:fontName>Helvetica-Bold</stFnt:fontName>
              <stFnt:fontFamily>Helvetica</stFnt:fontFamily>
              <stFnt:fontFace>Bold</stFnt:fontFace>
              <stFnt:fontType>TrueType</stFnt:fontType>
              <stFnt:versionString>5.0d8e2</stFnt:versionString>
              <stFnt:composite>False</stFnt:composite>
              <stFnt:fontFileName>Helvetica.dfont</stFnt:fontFileName>
           </rdf:li>
        </rdf:Bag>
     </xapTPg:Fonts>
     <xapTPg:PlateNames>

I want to copy the part that starts </xapTPg:Fonts> to </xapTPg:Fonts>

any help is very much appreciated

cheers dorn

Do you mean something like this? It saves the text between to strings to a new file.

Scripts:

property tid_1 : "<xapTPg:Fonts>"
property tid_2 : "</xapTPg:Fonts>"

on run
	set docChoose to chooseActiveTextEditDocument()
	
	-- missing value
	if docChoose is missing value then
		display dialog "No open documents in TextEdit" buttons "OK" default button 1
		return
	end if
	
	-- false
	if docChoose is false then return
	
	-- get text
	tell application "TextEdit" to set fullText to text of document docChoose
	set newText to getText of fullText from tid_1 to tid_2
	
	-- new
	set myFile to (choose file name with prompt "Choose the location to save the file")
	if myFile does not end with ".txt" then set myFile to (myFile & ".txt") as string
	
	-- write
	set OA to open for access myFile with write permission
	try
		write newText to OA starting at 0
		close access OA
	on error theMsg
		try
			close access OA
		end try
		display dialog "Writing to \"" & POSIX file of myFil & "\" failed:" & return & return & theMsg
	end try
end run

(* ===== HANDLERS ===== *)
on getText of someText from startingPoint to endingPoint
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to startingPoint
	
	try
		set v to text item 2 of someText
	on error
		return ""
	end try
	
	set AppleScript's text item delimiters to endingPoint
	
	try
		set v to text item 1 of v
	end try
	
	set AppleScript's text item delimiters to tid
	
	return v
end getText

on chooseActiveTextEditDocument() -- returns name or missing value or false
	set myActive to appIsActive("TextEdit")
	if myActive is true then
		tell application "TextEdit"
			-- if none
			if (count every document) is 0 then return missing value
			
			-- choose document
			set allNames to name of every document
		end tell
		set myChoice to (choose from list allNames)
		
		-- if canceled
		if myChoice is false then return false
		
		-- if normal
		set myChoice to myChoice as string
		
		return myChoice
		
	else -- not active
		return missing value
	end if
end chooseActiveTextEditDocument

on appIsActive(appName)
	tell application "System Events" to return (exists process appName)
end appIsActive

Hope it helps,
ief2

Hi ief2

Thats just blown my mind but works great!!!:smiley:

thanks for help!!

Cheers dorn