Adapted from one of Adobe’s sample scripts for AI CS3 - this will pull a list of all fonts used in a document into a plain text file.
--A stripped down version of Adobe's sample script "Analyze Documents"
tell application "Adobe Illustrator"
set docRef to document 1
set textItemList to every text frame of docRef
set fontList to ""
repeat with textart in textItemList
if ((count of characters in textart) > 0) then
set characterFont to the name of text font of character 1 of text of textart
if (not (fontList contains characterFont)) then
set fontList to fontList & characterFont & return
end if
end if
end repeat
end tell
set myPref to button returned of (display dialog (name of docRef) & " contains the following fonts:" & return & return & (fontList as text) & return & "Save font list as a text file?" buttons {"Cancel", "Save"} default button 2)
if myPref = "Save" then
set theText to "Fonts used in " & (name of docRef) & return & return & fontList as text
tell application "TextEdit"
set myDoc to (make new document with properties {text:theText})
tell myDoc
activate
end tell
end tell
end if
I used this code and it worked fine in Illustrator CS4. The problem for me is that sometimes a character is formatted in the middle of the paragraph and this code only picks up the first character. I modified the script to cover every character of every text frame.
But for documents with lots of text it takes a really long time. Also, it errors if there are any linked text frames. Has anyone got any better ideas for getting a list of fonts used in the document?
tell application "Adobe Illustrator"
set docRef to document 1
set textItemList to every text frame of docRef
set fontList to ""
repeat with textart in textItemList
set charCount to count of characters in textart
if charCount > 0 then
repeat with charNumber from 1 to charCount
set characterFont to the name of text font of character charNumber of text of textart
if (not (fontList contains characterFont)) then
set fontList to fontList & characterFont & return
end if
end repeat
end if
end repeat
end tell
set myPref to button returned of (display dialog (name of docRef) & " contains the following fonts:" & return & return & (fontList as text) & return & "Save font list as a text file?" buttons {"Cancel", "Save"} default button 2)
if myPref = "Save" then
set theText to "Fonts used in " & (name of docRef) & return & return & fontList as text
tell application "TextEdit"
set myDoc to (make new document with properties {text:theText})
tell myDoc
activate
end tell
end tell
end if
I also tried it with words instead of characters. That improved the speed and would pick up most of the extra formatting but it would ignore copyright and registered trademark symbols that are attached to a word. And it still errors with linked text frames.
Model: 2 x 2.8 GHz Quad-Core Intel Xeon
AppleScript: 2.1.2
Browser: Firefox 3.6.14
Operating System: Mac OS X (10.6)
Illustrator export font list - works better!!!
I had to have a solution that found all the fonts used, so the first character was not enough. Looping through each time would go really slowly on documents with lots of text, so I found it better to gather a list of all characters and then sort through the duplicates. My script also excludes some fonts that only appear in our information block. It also differs from the original script in that it places the result in a named text frame in the Illustrator document. And it gets rid of empty text frames.
I would be interested if anyone has any comments or improvements.
Ta
Dave
-- this script will record all the fonts used in the document,
-- with the exception of fonts in the list of information fonts
-- the information fonts are not dispatched with the job
-- captures the user's first name from the system for use later
set myName to (long user name of (system info))
set sp to (offset of " " in myName)
set myFirstName to text 1 thru (sp - 1) of myName
tell application "Adobe Illustrator"
activate
set thisDoc to document 1
-- gets rid of empty text frames
try
tell thisDoc
delete (every text frame whose contents is "")
end tell
on error
display dialog "Hi " & myFirstName & ". You probably have empty text fields on a hidden or locked layer." buttons {"Edit document"}
end try
-- get the long list of fonts used in the document
try -- because otherwise it crashes!
set allCharacterFontsList to get name of text font of every character of every story of thisDoc
end try
set infoFontsList to {"Font-1", "Font-2", "Font-3"} -- put your fonts to exclude here
set usedFontsList to {}
-- looks at the very long list of fonts and removes duplicates
repeat with x from 1 to count of items of allCharacterFontsList
set n to item x of allCharacterFontsList
if n is not in usedFontsList and n is not in infoFontsList then set end of usedFontsList to n
end repeat
if usedFontsList is {} then
set usedFontsList to "None"
end if
-- turns the list into a string separated by a comma and a space
set AppleScript's text item delimiters to ", "
set myFontList to usedFontsList as string
set AppleScript's text item delimiters to {""}
-- puts the font information into a named text frame in the illustrator document
if exists (text frame "titleblock-fonts" of thisDoc) then
set contents of text frame "titleblock-fonts" of thisDoc to myFontList
end if
activate
end tell
I can’t seem to get this to work in CS5… unless I am doing something wrong. I ran it from both the Applescript app and from inside Illustrator’s Presets/Scripts folder. It does delete the empty text frame but I never get a dialog box or a txt document.
Will this script work with CS5? Advice on what I could be doing incorrectly?
Thanks,
cindy in indy
Hi Cindy
Were you running the last script? There is a comment near the end that says it puts the results into a named text frame “titleblock-fonts”. The other scripts bring up dialog boxes and offer to save as text.
I’m running this on CS4 but my colleague is running CS5 and they both work. I’ve found it performs a lot better from the script menu in the menu bar, rather than from inside Illustrator’s script area. If you run it from Script Editor, click the Events button at the bottom and it should give you some feedback.
Interesting … I am using the very last script.
So odd. I put it in my FastScripts menu as well and I still can’t get it to work.
It does get rid of empty text frame but that seems to be as far as I get.
I have run it
while in the AppleScript editor
within Illustrator’s Script “Other Script” menu
and FastScripts
What are the events and replies (bottom of Script Editor)? This should show what is going wrong.
So do you have an exactly named text frame in Illustrator called titleblock-fonts? If you want to display a dialog instead use the (slightly modified) bit of code from the previous examples. Al I have changed is the variable names so that it all ties up.
set myPref to button returned of (display dialog (name of thisDoc) & " contains the following fonts:" & return & return & (myFontList as text) & return & "Save font list as a text file?" buttons {"Cancel", "Save"} default button 2)
if myPref = "Save" then
set theText to "Fonts used in " & (name of thisDoc) & return & return & myFontList as text
tell application "TextEdit"
set myDoc to (make new document with properties {text:theText})
tell myDoc
activate
end tell
end tell
end if
This code goes at the bottom.