Skip to main content
Participating Frequently
April 10, 2024
Question

How can I automatically export lists of font used in a file?

  • April 10, 2024
  • 3 replies
  • 2032 views

I have been dumped an archive of InDesign books layouts which were done 5+ years ago. Some of the fonts are obsolete and need to be replaced. There are hundreds of files in this archive.

 

I want a script to open each file, ignore the warning that the Links are missing, check the fonts in the document, and print this to a text file named for the document being checked, close the document and go on to the next one. I started playing around with the scripting tools but I've got stuck.

 

Has anyone solved this problem already? Googling has not been successful.

 

Thanks in advance for any help you can give!

This topic has been closed for replies.

3 replies

rob day
Community Expert
Community Expert
April 10, 2024

I started playing around with the scripting tools but I've got stuck.

 

Hi @Richard27439456ewpv , This JavaScript would write a text file in the same folder as the INDD file with a list of Type1 fonts used in the document:

 

 

var d = app.activeDocument
var f = d.fonts.everyItem().getElements()

var s = d.name + " Type 1 fonts: \r"
for (var i = 0; i < f.length; i++){
    if (f[i].fontType == 1718899761) {
        s += f[i].name + "\r"
    } 
};  
writeText(d.filePath + "/" + d.name + " Type1 Font List", s) 



function writeText(p,s){
    var file = new File(p);
    file.encoding = 'UTF-8';
    file.open('w');
    file.write(s);
    file.close();
}
Participating Frequently
April 10, 2024

Thanks everyone!

I will give all this a proper go tomorrow because my brain is tired. (UK based.)

Participating Frequently
April 23, 2024

Using ChatGPT to help, I embroidered your AppleScript to the following:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property RootPath : missing value
property NotCheckedFiles : {} -- List to store filenames of files not checked

set RootPath to ((choose folder with prompt "Please select a folder to process:") as text)

set Filelist to (list folder RootPath without invisibles)

repeat with f from 1 to count of items of Filelist
set NextName to (item f of Filelist)
if NextName ends with ".indd" then
MakeFontList(RootPath & NextName)
end if
end repeat

-- Save list of files not checked to "notchecked.txt"
set notCheckedFile to (open for access file (RootPath & "notchecked.txt") with write permission)
repeat with eachFile in NotCheckedFiles
write eachFile & linefeed to notCheckedFile starting at eof
end repeat
close access notCheckedFile

display dialog "Font extraction completed for all InDesign files." buttons {"OK"} default button "OK"

on MakeFontList(FilePath)
set TextOut to ("Family\tFont Style\tType\tPS Name\tLocation" & return)
set DocName to ""
tell application id "com.adobe.InDesign"
set user interaction level of script preferences to never interact
try
open file FilePath
tell document 1
set DocName to name
set DocName to CleanDocName(DocName) of me
log DocName
set n to fonts
end tell
repeat with i from 1 to count of items of n
try
tell item i of n
set FN to font family
set FS to font style name
set FT to font type
set PS to PostScript name
set LO to location
set LO to FN & tab & FS & tab & FT & tab & PS & tab & LO
set TextOut to TextOut & LO & return
end tell
on error errMsg
-- Handle font-related errors by logging
log errMsg
end try
end repeat
on error errMsg
-- Handle document-related errors by logging and adding filename to not checked list
log errMsg
set end of NotCheckedFiles to FilePath -- Add filename to the list of not checked files
end try
close document 1 saving no -- Close the document after processing or in case of error
set user interaction level of script preferences to interact with all
end tell
set NewFile to (open for access file (RootPath & DocName & ".txt") with write permission)
write TextOut to NewFile starting at eof
close access NewFile
end MakeFontList

on CleanDocName(n)
set AppleScript's text item delimiters to {""}
set n to ((characters 1 thru -6 of n) as text)
return n
end CleanDocName

This analyses the folder of INDD files, prints the fonts used into text files, and makes a text file of any file it failed to analyse. It prints a 'finished' message when it ends.

So that's really useful. 

Thanks to everyone for your help!!

 


Very glad to hear you got this to work — 700 books is quite a pile!

 

Participating Frequently
April 10, 2024

I have written something very similar in the past.

Do you just want a list of the font names or do you need to know the font type, for instance, to see Type 1 fonts that need to be replaced?

Are the InDesign documents all in one place and how many hundreds are we talking about?

 

Participating Frequently
April 10, 2024
This AppleScript may do what you want.  
You would need to paste it into Script Editor and run it from that or save it as a compiled script and run it from InDesign's script palette. 
When you paste it, make sure the quotation marks don't get smartened. 

 

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property RootPath : missing value

set RootPath to ((choose folder with prompt "Please select a folder to process:") as text)

set Filelist to (list folder RootPath without invisibles)

repeat with f from 1 to count of items of Filelist
	set NextName to (item f of Filelist)
	if NextName ends with ".indd" then
		MakeFontList(RootPath & NextName)
	end if
end repeat

on MakeFontList(FilePath)
	set TextOut to ("Family	Font Style	Type	PS Name	Location" & return)
	tell application id "com.adobe.InDesign"
		set user interaction level of script preferences to never interact
		open file FilePath
		tell document 1
			set DocName to name
			set DocName to CleanDocName(DocName) of me
			log DocName
			set n to fonts
		end tell
		repeat with i from 1 to count of items of n
			tell item i of n
				set FN to font family
				set FS to font style name
				set FT to font type
				set PS to PostScript name
				set LO to location
				set LO to FN & tab & FS & tab & FT & tab & PS & tab & LO
				set TextOut to TextOut & LO & return
			end tell
		end repeat
		close document 1
		set user interaction level of script preferences to interact with all
	end tell
	set NewFile to (open for access file (RootPath & DocName & ".txt") with write permission)
	write TextOut to NewFile starting at eof
	close access NewFile
end MakeFontList

on CleanDocName(n)
	set AppleScript's text item delimiters to {""}
	set n to ((characters 1 thru -6 of n) as text)
	return n
end CleanDocName

 

Robert at ID-Tasker
Legend
April 10, 2024

If you work on a PC - yes, my tool can do that - and a lot more.

 

Participating Frequently
April 10, 2024

Hi Robert,

I've got a Windows PC and a Mac. The InDesign is on the Mac but I could get a PC licence to help with this task.


What is your tool?

Thanks....

Robert at ID-Tasker
Legend
April 10, 2024

In my sig - ID-Tasker.