• 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: Font book scripts in 10.8.x? Is this another sandboxing issue?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Font book scripts in 10.8.x? Is this another sandboxing issue?


  • Subject: Re: Font book scripts in 10.8.x? Is this another sandboxing issue?
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 21 Aug 2013 20:26:43 +0100

Alex Zavatone wrote on Tue, 20 Aug 2013 16:09:01 +0000 (GMT):

>I just had to use a temp Mac for a while and while trying to run the
Create
>Font Sample font book script under 10.8.x, When it completes, it
displays
>this in TextEdit:
>
>Font Samples - 0 families   0 typefaces
>
>Things like this are really frustrating when using a new version of the
OS,
>because they used to work in the older one, and it wastes people's time.

As Yvan's already pointed out, the script does work in 10.8.x, provided
you're expecting it to do what it does: create a TextEdit document
containing examples of fonts currently selected in FontBook. But there's
nothing in the comments to tell you this and the script itself is
somewhat inefficient, contains nested 'tells' to different applications,
etc. A typical example script!  ;)

If your time's at a premium, this version's faster:

  -- Creates a TextEdit document ahowing examples of the font(s) selected in FontBook.
  on main()
    script o
      property allIDs : missing value
      property allFamilyNames : missing value
      property allPSNames : missing value
      property selectedTypefaces : missing value
    end script

    tell application "System Events"
      set wasTextEditRunning to (name of application processes contains "TextEdit")
    end tell

    tell application "Font Book"
      set {o's allIDs, o's allFamilyNames, o's allPSNames} to {ID, family name, PostScript name} of typefaces
      set totalFaces to (count o's allIDs)

      set numFamilies to (count selected font families)
      set o's selectedTypefaces to selection
      set numFaces to count o's selectedTypefaces
    end tell

    tell application "TextEdit"
      if (wasTextEditRunning) then
        make new document at the end of documents of it
      end if
      tell the front document
        make new paragraph at end of paragraphs with data "Font Samples - " & ¬
          numFamilies & " families   " & ¬
          numFaces & " typefaces" & return & return with properties {size:18}
      end tell
    end tell

    --  asuuming that items in selection are sorted in font family.

    set currentFamilyName to ""
    repeat with i from 1 to numFaces
      tell application "Font Book"
        set thisID to ID of item i of o's selectedTypefaces
      end tell

      repeat with j from 1 to totalFaces
        if item j of o's allIDs is thisID then exit repeat
      end repeat

      set familyName to item j of o's allFamilyNames
      set psName to item j of o's allPSNames

      if (familyName is not currentFamilyName) then
        set currentFamilyName to familyName
        tell the front document of application "TextEdit"
          if (j is 1) then
            make new paragraph at end of paragraphs with data familyName & return with properties {font:"LucidaGrande", size:14}
          else
            make new paragraph at end of paragraphs with data return & familyName & return with properties {font:"LucidaGrande", size:14}
            set size of paragraph -2 to 12
          end if
        end tell
      end if
      try
        tell the front document of application "TextEdit"
          make new paragraph at end of paragraphs with data tab & psName & return with properties {font:psName, size:12}
        end tell
      end try

    end repeat
    tell application "TextEdit" to activate
  end main

  main()


NG


 _______________________________________________
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


  • Follow-Ups:
    • Re: Font book scripts in 10.8.x? Is this another sandboxing issue?
      • From: Alex Zavatone <email@hidden>
  • Prev by Date: Re: AS and Excel
  • Next by Date: Re: Font book scripts in 10.8.x? Is this another sandboxing issue?
  • Previous by thread: Re: Font book scripts in 10.8.x? Is this another sandboxing issue?
  • Next by thread: Re: Font book scripts in 10.8.x? Is this another sandboxing issue?
  • Index(es):
    • Date
    • Thread