ID list of fonts used

I’m trying to get a list of all the fonts used in a bunch of InDesign documents, with their type (TTF, OTF, Type1, etc), status (missing or available), the name of the file, and generate a text file with the results. Any advice on this project will be appreciated. Thanks!
I’m getting stuck with error Can’t make name of «class pacd» of «class pacd» of application “Adobe InDesign 2020” into type string.

set source_folder to choose file with prompt "Select folder containing Indesign Docs to get a font report" with multiple selections allowed without invisibles

tell application "Finder" to set item_list to every item of source_folder

--write results to "indesign font report.txt"
set thisFile to (path to desktop as text) & "indesign font report.txt"

--loop thru all ID docs
repeat with this_item in item_list
	set doc_kind to kind of (info for this_item as alias)
	if doc_kind contains "Indesign" then
		--only ID documents
		tell application id "com.adobe.indesign"
			activate
			-- no dialogs
			set user interaction level of script preferences to never interact
			open this_item
			tell active document
				
				set x to name of fonts
				
				set myData to (name of active document as string) & return
			end tell
			
			--put prefs back
			set user interaction level of script preferences to interact with all
			
			my write_to_file(myData, thisFile, true)
			close document 1 saving no
			
			
		end tell
	end if
end repeat

---==============
on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as string
		set the open_target_file to open for access file target_file with write permission
		if append_data is false then set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file


Browser: Safari 537.36
Operating System: macOS 10.14

Assuming that you’re referring to the line below, it is probably because you are doubling up on ‘active document’, because of the preceding ‘tell active document’ line.
[format] set myData to (name of active document as string) & return
[/format]
The script is interpreting the combination of the two, along the lines of:

[format]set myData to (name of active document as string) of active document & return[/format]

Hence the error. Note as well that you don’t have ‘active document’ as part of the ‘name of fonts’ line.

Try something like:

[format]set myData to name & return[/format]

NB The ‘as string’ shouldn’t be required, since the name of the document should already be text (although perhaps InDesign has a unique way of handling document names).

Thank you Mockman for your quick response. I decided to simplify what I need and made some edits. The script below creates a text file with all the fonts used in the ID document + it creates an extra line listing Type1 fonts but when it finds a document that doesn’t have a Type1 font it just skips it. The purpose is to have all the fonts used + identified the ones that are type1. How do I do achieve that?

set sourceFolder to choose folder
tell application "Finder"
	set fileList to files of sourceFolder whose name extension is "indd"
	set sourceFolderName to name of sourceFolder
end tell
set theFile to (path to desktop as text) & sourceFolderName & ".txt"
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
try
	set datastream to open for access file theFile with write permission
	write (sourceFolder as text) & return & return to datastream
	
	tell application "Adobe InDesign 2020"
		set user interaction level of script preferences to never interact
	end tell
	
	repeat with aFile in fileList
		set currentFile to aFile as text
		tell application "Adobe InDesign 2020"
			
			set doc to open file currentFile
			set docName to name of doc
			try
				--list all all fonts used
				set usedFonts to name of fonts of doc
				
				--List all type1 postscript  fonts used
				set type1Fonts to (name of fonts of doc whose font type is type 1)
				
				write "Document : " & docName & return to datastream
				write (usedFonts as string) & return & return to datastream
				write ("These are Type1 PS:  " & return & type1Fonts as string) & return & return to datastream
			end try
			close doc saving no
		end tell
	end repeat
	
	tell application "Adobe InDesign 2020"
		set user interaction level of script preferences to interact with all
	end tell
	close access datastream
on error e
	display dialog "An error occurred: " & e
	try
		close access file theFile
	end try
end try
set AppleScript's text item delimiters to ASTID
--say "done! Check desktop for the font report"
--display dialog "Done!" buttons {"OK Yay!"} with icon 1 default button 1 giving up after 4

Browser: Safari 537.36
Operating System: macOS 10.14

I’m not at all knowledgeable about indesign, so I can only speculate here. What does ‘name of font’ output, and what does it output when a document has no matching fonts? If it generates an error, then your try statement is obscuring it and causing your skip (although you don’t specify what is being skipped).

I’d remove the try/end try around the ‘set type1Fonts’ line and see what happens. Actually, for troubleshooting, I’d remove pretty much everything and just work with the active document and see what the output is for each of the ‘name of font’ lines.

I removed the try statement & I see now why it was skipping those files:
An error occurred: Adobe InDesign 2020 got an error: Can’t get name of every font of document id 892 whose font type = type 1.

I guess an “if statement” needs to be used. How do I get around that? Like if type1 is not found then continue.

There are probably a couple of approaches you could take. If/then could probably work if you can find a question that doesn’t trigger an error, e.g. if exists (fonts of doc whose font type is type 1) then. However, I can’t determine whether that will generate a ‘false’ or an error but something like that would likely work.

You could also keep the try statement but have an ‘on error’ section (which is sort of like ‘else’ in an if/then statement).

In that section, you manually set type1Fonts to an empty string or something that will integrate with your subsequent write statement. You could also specify the error so that if a different one occurs, it won’t be handled here.

For example:

try
	set type1Fonts to (name of fonts of doc whose font type is type 1)
on error
	set type1Fonts to "" -- or
	set type1Fonts to "0 type 1 fonts in document"
end try

You can get more details on usage here:
Control Statements Reference
https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_control_statements.html#//apple_ref/doc/uid/TP40000983-CH6g-128973

I would probably just get a type list, rather than specifying them and coming up with various conditionals to avoid errors for those scenarios. If there are no fonts in that class, they won’t be collected. There’s no need for the triple write in post three, as you could do that in one operation; I prefer to avoid the opening and closing cycle altogether.

set concated to {}
tell application "Adobe InDesign CS3"'s document 1 --adjust as needed
	set {Fnom, Ftype, Fstatus} to fonts's {name, font type, status}
end tell
repeat with counter from 1 to count Fnom
	set concated's end to {Fnom's item counter, " — ", Ftype's item counter, ", ", Fstatus's item counter} & return
end repeat
tell application "Finder" to set isTarget to ((make file) as alias)
write (concated as text) to isTarget

That worked! THANK YOU! MarcAnthony & Mockman for all your help:D

I found a small obstacle. Some files have missing fonts & which is stopping the process. I’m getting an → error “The requested font family is not available.” number 15875. How do I ignore the missing font & continue?

tell application id "com.adobe.InDesign"
			set doc to open file currentFile
			set docName to name of doc
			set {Fnom, Ftype} to fonts's {name, font type} of document 1
			
			repeat with counter from 1 to count Fnom
				set concated's end to {Fnom's item counter, Ftype's item counter} & return
			end repeat
			
			write "Document : " & docName & return to datastream
			write (concated as string) to datastream 
			
			close doc saving no
		end tell

Browser: Safari 537.36
Operating System: macOS 10.14

You could incorporate the same ignoring statements as in the original code, however, I would think you’d want to account for missing items; the condition might be filtered with a whose clause at the time the variables are set:
[format]set Ftype to fonts’s type whose status is not missing —or whatever the negative status may be
[/format]
or
[format](fonts whose status is not missing)'s type[/format]
Alternatively, you might actually need a conditional if statement that makes sure the font exists, prior to extracting properties. I don’t have any missing fonts and limited time at the moment to test options.

Write is a standard addition and should live outside your InDesign tell block. I’d advise concatenating your two writes, so you aren’t issuing multiple events:

[format]write "Document : " & docName & return & (concated as string) to datastream [/format]