Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'i got this working, here's the script:' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
i got this working, here's the script:
Authored by: SimonDorfman.com on Feb 14, '04 06:01:03PM
this requires this script to run.

property sttr : missing value

--> modify the following as needed
if sttr is missing value then
	set sttr to load script alias "Macintosh HD:Library:Scripts:StyledTextToRecord:StyledText <-> Record.scpt"
end if


display dialog "I will take the contents of the clipboard (styled text, please) and convert everything to plain text, except for bolds and italics" with icon note

set clipContents to (the clipboard) as styled text

tell sttr to copy StyledTextToRecord(clipContents) to styleInfo

--> get default styles to reset all
tell sttr to copy StyledTextToRecord("x" as Unicode text) to defaultStyleInfo

repeat with i from 1 to count styleInfo's stylesOn
	set x to styleInfo's stylesOn's item i
	if x is not {plain} then
		if x contains bold and x contains italic then
			set styleInfo's stylesOn's item i to {bold, italic}
		else if x contains bold then
			set styleInfo's stylesOn's item i to {bold}
		else if x contains italic then
			set styleInfo's stylesOn's item i to {italic}
		else
			set styleInfo's stylesOn's item i to {plain}
		end if
	end if
	--> colors and others out!
	set styleInfo's stylesHeights's item i to defaultStyleInfo's stylesHeights's item 1
	set styleInfo's stylesAscents's item i to defaultStyleInfo's stylesAscents's item 1
	set styleInfo's stylesFontIDs's item i to defaultStyleInfo's stylesFontIDs's item 1
	set styleInfo's stylesSizes's item i to defaultStyleInfo's stylesSizes's item 1
	set styleInfo's stylesColors's item i to {0, 0, 0}
end repeat

set the clipboard to (sttr's RecordToStyledText(styleInfo))

beep 2
here's the applescrit.net forum page where people helped me figure this out: Link

[ # ]
i got this working, here's the script:
Authored by: paulrob on Feb 15, '04 07:32:43AM
This is excellent! Does what it says on the tin! Well, almost. Although you get bolds etc, it isn't plain text - the font is Geneva. For some reason Applescript assigns what you might expect to be a plain text to a Geneva font! See my previous post on this. And the original poster's comments. It's to do with the seed value "x" on the line: -

tell sttr to copy StyledTextToRecord("x" as Unicode text) to defaultStyleInfo
Unfortunately, Applescript assigns this "x" a Geneva font right from the start. Therefore, Gevena becomes the default font for the clipboard. I tried the following as a replacement, based on what the original poster said: -

set seed_char to «class ktxt» of (("x" as Unicode text) as record)
tell sttr to copy StyledTextToRecord(seed_char) to defaultStyleInfo
but now the handler throws up an error claiming the clipboard has non-styled text. Sounds like a bit of work on the handler might straighten this out, and then you would have "real" plain text with style info, but not font.

[ # ]