Changing illustrator fonts in many files by batching



I have many illustrator files in which I need to change the fonts. I found a script in one of the forums here that will work on each individual ai.file. (I modified it with the fonts I’m replacing) I also found a script here that will open up a source folder and batch change every file in that folder, but it uses a different action to change the font. So I tried to combine the parts from each script that seemed pertinent to what I want to do. The combined script will change the font in the first file I open but will not batch the files in the rest of the folder. It gives me an error.

This is the script that works on the individual files:

set swaplist to {{"PalatinoLT-Bold", "PalatinoLTStd-Bold"}, {"PalatinoLT-Roman", "PalatinoLTStd-Roman"}, {"PalatinoLT-BoldITalic", "PalatinoLTStd-BoldItalic"}}
tell application "Adobe Illustrator"
	activate
	tell document 1
		delete (every text frame whose contents is "")
		repeat with i from 1 to count of swaplist
			try
				set text font of (every character of every story whose properties contains {text font:text font (item 1 of item i of swaplist)}) to text font (item 2 of item i of swaplist) of application "Adobe Illustrator"
			end try
		end repeat
	end tell
end tell

this is the script I’m taking the “Find source folder and apply to all” info from:

--get a sourceFolder that holds the files to print 
set sourceFolder to (choose folder with prompt "Choose a folder with files to print:")


-- get a list of files of the files to be printed in the sourceFolder 
tell application "Finder" to set workingFiles to (every file of folder sourceFolder) as alias list
repeat with workingFile in workingFiles
	tell application "Adobe Illustrator"
		open workingFile
		--do script "find and replace font" from "Eliz" without dialogs
		--do script "Action 1" from "Eliz" without dialogs
		close document 1 saving no
	end tell
end repeat

This is how I combined the 2:

--get a sourceFolder that holds the files to print 
set sourceFolder to (choose folder with prompt "Choose a folder with files to print:")


-- get a list of files of the files to be printed in the sourceFolder 
tell application "Finder" to set workingFiles to (every file of folder sourceFolder) as alias list
repeat with workingFile in workingFiles
	tell application "Adobe Illustrator"
		open workingFile


set swaplist to {{"PalatinoLT-Bold", "PalatinoLTStd-Bold"}, {"PalatinoLT-Roman", "PalatinoLTStd-Roman"}, {"PalatinoLT-BoldItalic", "PalatinoLTStd-BoldItalic"}}
tell application "Adobe Illustrator"
	activate
	tell document 1
		delete (every text frame whose contents is "")
		repeat with i from 1 to count of swaplist
			try
				set text font of (every character of every story whose properties contains {text font:text font (item 1 of item i of swaplist)}) to text font (item 2 of item i of swaplist) of application "Adobe Illustrator"
			close document 1 saving no
	end tell
end repeat

this is the error message I get:

Syntax Error
Expected “end” or “on” but found “end tell”.

I am a complete newbie to scripts and have no idea what the issue is. Can someone help me to get this to run?

Thanks!

Hi. In the same way that parenthesized text needs both open and close parentheses, a block needs both a tell and an end tell or a repeat and an end repeat. The message simply means you tried to terminate one type of command block using the other.

Edit: In the combined script, you also called the application “Adobe Illustrator” twice.

Marc Anthony, Thank you for your help. This is how I finally got it to work.

--get a sourceFolder that holds the files to print 
set sourceFolder to (choose folder with prompt "Choose a folder with files to print:")

set swaplist to {{"PalatinoLT-Bold", "PalatinoLTStd-Bold"}, {"PalatinoLT-Roman", "PalatinoLTStd-Roman"}, {"PalatinoLT-BoldItalic", "PalatinoLTStd-BoldItalic"}, {"PalatinoLT-Italic", "PalatinoLTStd-Italic"}, {"PalatinoLT-Medium", "PalatinoLTStd-Medium"}}
-- get a list of files of the files to be printed in the sourceFolder 
tell application "Finder" to set workingFiles to (every file of folder sourceFolder) as alias list
repeat with workingFile in workingFiles
	tell application "Adobe Illustrator"
		set user interaction level to never interact
		open workingFile without dialogs
		activate
		tell document 1
			delete (every text frame whose contents is "")
			repeat with i from 1 to count of swaplist
				try
					set text font of (every character of every story whose properties contains {text font:text font (item 1 of item i of swaplist)}) to text font (item 2 of item i of swaplist) of application "Adobe Illustrator"
				end try
			end repeat
		end tell
		close document 1 saving yes
	end tell
end repeat

My new problem is that I want to change the font names from Palatino to Minion so that I can replace the Minion fonts in my files to Minion Pro. It works for Minion Regular but not for Minion Italic. I assume it has to do with how the fonts are named in the file and how I enter them into the script but I haven’t found the right combination yet. Any thoughts on how to get the correct name?

Thanks.

Hello, again.

–this returns ALL loaded fonts:

tell application "Adobe Illustrator" to text fonts's name 

Minion truncates “Italic” to “It;” the family should be:
{“MinionPro-BoldCn”, “MinionPro-BoldCnIt”, “MinionPro-Regular”, “MinionPro-It”, “MinionPro-Medium”, “MinionPro-MediumIt”, “MinionPro-Semibold”, “MinionPro-SemiboldIt”, “MinionPro-Bold”, “MinionPro-BoldIt”}

Hi Beth,

Nice script.

When processing multiple files, from a folder, I tend to put the main repeat loop within the ‘tell application’ block. That way I’m not repeating the ‘tell application’ bit as I’ve already activated it the first time round. I like to think that’s beneficial in some way (I’m sure someone will correct me if I’m wrong ;)).

I also move things like setting prefs outside the repeat loop so’s not to repeat something I only need to do the once. When processing large numbers of files I try to shave off as much time as I can.


--get a sourceFolder that holds the files to print 
set sourceFolder to (choose folder with prompt "Choose a folder with files to print:")

set swaplist to {{"PalatinoLT-Bold", "PalatinoLTStd-Bold"}, {"PalatinoLT-Roman", "PalatinoLTStd-Roman"}, {"PalatinoLT-BoldItalic", "PalatinoLTStd-BoldItalic"}, {"PalatinoLT-Italic", "PalatinoLTStd-Italic"}, {"PalatinoLT-Medium", "PalatinoLTStd-Medium"}}
-- get a list of files of the files to be printed in the sourceFolder 
tell application "Finder" to set workingFiles to (every file of folder sourceFolder) as alias list

tell application "Adobe Illustrator"
	activate
	
	set user interaction level to never interact
	
	repeat with workingFile in workingFiles
		
		open workingFile without dialogs
		
		tell document 1
			delete (every text frame whose contents is "")
			repeat with i from 1 to count of swaplist
				try
					set text font of (every character of every story whose properties contains {text font:text font (item 1 of item i of swaplist)}) to text font (item 2 of item i of swaplist) of application "Adobe Illustrator"
				end try
			end repeat
		end tell
		
		close document 1 saving yes
		
	end repeat
	
end tell

HTH

It doesn’t make any difference…

But that does…

Hi Shane,

Thanks for pointing me in the right direction.

Just to dig a little deeper on the first point.
If you put the tell application inside the loop, instead of outside it, are you not making repeated calls to the app? And, if so, why is not better to just call the app the once? The question is to further my understanding of what’s happening, so don’t take it the wrong way :).

Thanks Shane.

I don’t know that activate is performance intensive; if there is any impact, it might need massive iterative numbers to be measurable. I would say, stylistically, your arrangement is better, but repeated calls are being made to the application, in either case, because both command sets are directed to objects within the app’s’ scope.

You are anyway. Have a look in the event log to see what events actually get sent – that’s what matters.

A simple “tell application” statement does nothing by itself; it just provides a context for the statements inside the block.