• 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: Michelle Steiner <email@hidden>
  • Date: Thu, 27 Mar 2008 16:39:39 -0700

On Mar 27, 2008, at 3:29 PM, 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. 

Here is my solution; it will set a random number of characters, never to exceed 1/10 of the remaining characters in the document, to a random typeface.  (I used your three.)

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

set start to 1
tell application "TextEdit" to set c to get count of characters of text of document 1
repeat until flag
if start is less than c then
set finish to random number from start to ((c - start) div 10) + start
else
set finish to c
set flag to true
end if
set fontChoice to some item of fontList
tell application "TextEdit" to set font of characters start through finish of text of document 1 to fontChoice
set start to finish + 1
end repeat

Change "characters" to "words" in the script to avoid changing fonts in the middle of a word.  Or use "sentences" or "paragraphs" to change on that basis.

-- 
Democrats think the glass is half full.  Republicans think the glass is theirs


 _______________________________________________
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: iTunes: Why can't I get properties.
  • Previous by thread: Re: 3 random typefaces intermixed
  • Next by thread: Re: 3 random typefaces intermixed
  • Index(es):
    • Date
    • Thread