• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 3 random typefaces intermixed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 3 random typefaces intermixed


  • Subject: Re: 3 random typefaces intermixed
  • From: deivy petrescu <email@hidden>
  • Date: Thu, 27 Mar 2008 19:39:12 -0400


On Mar 27, 2008, at 18:29, Mark J. Reed wrote:
Well, this works:

set fontList to ["TimesNewRomanPSMT", "Tahoma", "LucidaHandwriting- Italic"]
set text item delimiters to ""


tell application "TextEdit"
	set c to get count of characters of text of document 1
	repeat with i from 1 to c
		set fontIndex to random number from 1 to 3
		set fontChoice to item fontIndex of fontList
		set font of character i of text of document 1 to fontChoice
	end repeat
end tell

But it is, as Doug said, dog slow.  In fact, just

repeat with i from 1 to c
-- do nothing
end repeat

takes forever inside a TextEdit tell block.  Looping outside TextEdit
is fast, but adding the tell inside the loop brings the slowness right
back.

TextEdit supports the idea of "attribute runs"; I can imagine that if
instead of setting the font on each individual character, you first
decided (randomly) how many in a row to set and did them all in one
go, it might help a little, but I couldn't figure out how to make a
new attribute run of a certain size out of existing text.

Following your lead Mark, I've made some changes and it is significantly faster if you use the following


________________
___<script>
set fontList to ["TimesNewRomanPSMT", "Tahoma", "LucidaHandwriting- Italic"]


tell application "TextEdit" to tell document 1 to tell its text
repeat with j from 1 to count of paragraphs
repeat 1 times
if word 1 of paragraph j = return then exit repeat
tell paragraph j to repeat with i from 1 to count of word
set font of attribute run of word i to (contents of some item of fontList)
end repeat
end repeat
end repeat
end tell
________________
___</script>


Deivy

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: 3 random typefaces intermixed (From: Doug <email@hidden>)
 >Re: 3 random typefaces intermixed (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: 3 random typefaces intermixed
  • Next by Date: Re: 3 random typefaces intermixed
  • Previous by thread: Re: 3 random typefaces intermixed
  • Next by thread: Re: 3 random typefaces intermixed
  • Index(es):
    • Date
    • Thread