I am a relative beginner to applescript and have attempted to adapt scripts that I have found on this site for my needs.
I need to find the text font of various characters that appear in a text frame in Illustrator, find the text font and then add it to a list of fonts. I have based this on the script posted by misterfriendly here:
http://macscripter.net/viewtopic.php?id=25034
The problem with his script is that because it only looks at the first characters it will miss characters further on in the text that have different formatting. The ultimate aim for me is to have a list of all fonts used in the document. I will then put this list into a text frame in our slug. (This last bit I haven’t done yet, but I feel confident I can do that!)
Here is my attempt at the script:
tell application "Adobe Illustrator"
set docRef to document 1
set findCharacters to {"®", "â„¢"}
set textItemList to every story 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
repeat with i from 1 to count of findCharacters -- the idea is to work through the list
set characterFont to the name of text font of character (item i of findCharacters) of text of textart
if (not (fontList contains characterFont)) then
set fontList to fontList & characterFont & return
end if
end repeat
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 get: error “Adobe Illustrator got an error: The collection does not support getting elements by name” number 1304 from text “®” of every text of story 1 of document 1
I would greatly appreciate any help on this, I am tearing my hair out!