2 Replies Latest reply on Jul 24, 2007 3:18 AM by (Johan_De_Deyne)

    AppleScript font sampler

    Level 1
      Gang--<br /><br />Here's an AppleScript that creates a font sampler:<br /><br /><pre>--FontSampler<br />--This script creates a font sampler from all of the fonts currently available to InDesign.<br />--Note: Turn off the Show List of Problem Tags Before Place option in the Tagged Text Import Options<br />--dialog box before you run this script.<br />set myFile to choose file name with prompt "Save tagged text file as:"<br />set myFamilyNames to {}<br />set myStyleNames to {}<br /><br />tell application "InDesign 2.0.2"<br />     set myFamilyNames to family of fonts<br />     set myStyleNames to style of fonts<br />end tell<br /><br />repeat with myCounter from 1 to (count myFamilyNames)<br />     if myCounter = 1 then<br />          my write_to_file("<ASCII-MAC>" & return, myFile, false)<br />          my write_to_file("<Version:2.000000><FeatureSet:InDesign-Roman><ColorTable:=<Black:COLOR:CMY K:Process:0.000000,0.000000,0.000000,1.000000>>" & return, myFile, true)<br />     else<br />          set myString to "<ParaStyle:>Font Family: " & item myCounter of myFamilyNames<br />          set myString to myString & " Font Style: " & item myCounter of myStyleNames & return<br />          set myString to myString & "<ParaStyle:><cFont:" & item myCounter of myFamilyNames & ">"<br />          set myString to myString & "<cTypeface:" & item myCounter of myStyleNames & ">"<br />          --Your example string goes here (for more example strings, use google to search for "pangram"):<br />          set myString to myString & "Sphinx of black quartz, judge my vow!" & return<br />          my write_to_file(myString, myFile, true)<br />     end if<br />end repeat<br /><br />set myFileName to (myFile as string)<br /><br />tell application "InDesign 2.0.2"<br />     set myDocument to make document<br />     tell page 1 of myDocument<br />          set myX to margin left of margin preferences<br />          set myY to margin top of margin preferences<br />          place myFileName place point {myX, myY} with autoflowing<br />     end tell<br />end tell<br /><br />--Write to file routine from Apple's AppleScript Guidebook module "Essential subroutines." <br />on write_to_file(this_data, target_file, append_data)<br />     try<br />          set the target_file to the target_file as text<br />          set the open_target_file to ¬<br />               open for access file target_file with write permission<br />          if append_data is false then ¬<br />               set eof of the open_target_file to 0<br />          write (this_data as international text) to the open_target_file starting at eof<br />          close access the open_target_file<br />          return true<br />     on error<br />          try<br />               close access file target_file<br />          end try<br />          return false<br />     end try<br />end write_to_file<br /></pre><br /><br />Thanks,<br /><br />Ole
        • 1. Re: AppleScript font sampler
          Thanks Ole!
          • 2. Re: AppleScript font sampler
            Hi,<br /><br />I've tweaked the script to work with ID CS3.<br /><br />Regards,<br />Johan<br /><br />>--FontSampler <br />--This script creates a font sampler from all of the fonts currently available to InDesign. <br />--Note: Turn off the Show List of Problem Tags Before Place option in the Tagged Text Import Options <br />--dialog box before you run this script. <br />set myFile to choose file name with prompt "Save tagged text file as:"<br />set myFamilyNames to {}<br />set myStyleNames to {}<br /><br />>tell application "Adobe InDesign CS3"<br />     set myFamilyNames to name of every font<br />end tell<br /><br />>repeat with myCounter from 1 to (count myFamilyNames)<br />     if myCounter = 1 then<br />          my write_to_file("<ASCII-MAC>" & return, myFile, false)<br />          my write_to_file("<Version:2.000000><FeatureSet:InDesign-Roman><ColorTable:=<Black:COLOR:CMY K:Process:0.000000,0.000000,0.000000,1.000000>>" & return, myFile, true)<br />     else<br />          set myFullFont to item myCounter of myFamilyNames<br />          set oldDelimiters to AppleScript's text item delimiters<br />          set AppleScript's text item delimiters to "     "<br />          set myList to every text item of myFullFont<br />          set myFamilyName to item 1 of myList<br />          set myStyle to item 2 of myList<br />          --display dialog "fam : " & myFamilyName & " sty : " & myStyle<br />          set myString to "<ParaStyle:>Font Family: " & myFamilyName<br />          set myString to myString & " Font Style: " & myStyle & return<br />          set myString to myString & "<ParaStyle:><cFont:" & myFamilyName & ">"<br />          set myString to myString & "<cTypeface:" & myStyle & ">"<br />          --Your example string goes here (for more example strings, use google to search for "pangram"): <br />          set myString to myString & "Sphinx of black quartz, judge my vow!" & return<br />          my write_to_file(myString, myFile, true)<br />     end if<br />end repeat<br /><br />>set myFileName to (myFile as string)<br />tell application "Adobe InDesign CS3"<br />     set myDocument to make document<br />     tell page 1 of myDocument<br />          set myX to left of margin preferences<br />          set myY to myX<br />          place myFileName place point {myX, myY} with autoflowing<br />     end tell<br />end tell<br /><br />>--Write to file routine from Apple's AppleScript Guidebook module "Essential subroutines."  <br />on write_to_file(this_data, target_file, append_data)<br />     try<br />          set the target_file to the target_file as text<br />          set the open_target_file to ¬<br />               open for access file target_file with write permission<br />          if append_data is false then ¬<br />               set eof of the open_target_file to 0<br />          write (this_data as international text) to the open_target_file starting at eof<br />          close access the open_target_file<br />          return true<br />     on error<br />          try<br />               close access file target_file<br />          end try<br />          return false<br />     end try<br />end write_to_file