TextEdit to edit text based on size.

Hi All,

I have a text file which I can use AS to open and set the contents to a variable, but I’m unsure of the syntax to get the properties of the paragraphs (Ie. Font, Size, colour etc)… I want to delete some paragraphs based on size. Is this doable? or is there a better approach for Rich Text manipulation with AS.

tell application "TextEdit"
	activate
	set mydoc to the document 1
	set firstpara to paragraph 1 of mydoc
	-- return firstpara
	set paraprop to the size of firstpara
	return paraprop
end tell

Using RTF in TextEdit with one line.
Hello World
(24pt, Helvetica Regular).

Returns
error “Can’t get size of "Hello World
".” number -1728 from size of "Hello World
"

Thanks in Advance.

Hello.

A better approach, would be to do the manipulation from Microsoft Word.

Hi,

try this


tell application "TextEdit"
	set mydoc to the document 1
	set paraprop to properties of paragraph 1 of text of mydoc
	return size of paraprop
end tell

Hi.

The line .

set firstpara to paragraph 1 of mydoc

. sets the variable to some AppleScript text. You need to get the paragraph information directly from the document.

tell application "TextEdit"
	activate
	set mydoc to the document 1
	set paraprop to the size of paragraph 1 of mydoc -- Get the size directly from the document.
	return paraprop
end tell

Or:

tell application "TextEdit"
	activate
	set mydoc to the document 1
	set firstpara to a reference to paragraph 1 of mydoc -- A reference to the paragraph in the document rather than text returned to the script.
	set paraprop to the size of firstpara
	return paraprop
end tell

Hi Nigel,

It was the ‘reference to’ command I was missing.

set firstpara to a reference to paragraph 1 of mydoc

Thanks a bunch.

Cheers.

Matt.

Hi Stefan, Fast and concise as always. Thanks.