Last active
December 29, 2015 00:59
-
-
Save akaleeroy/7589312 to your computer and use it in GitHub Desktop.
LoadFonts SendTo Command
- Load missing fonts required by an Illustrator file from the folder where you keep your font library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setLocal EnableDelayedExpansion | |
cd /d %~dp1 | |
set init=init-%RANDOM%.tmp | |
set clean=clean-%RANDOM%.tmp | |
set fp=%~n1.fonts.txt | |
:: EDIT THIS LINE with the location of your own font collection folder | |
set fontdir="F:\Fonts" | |
if exist "%fp%" goto Unload | |
:: First type of scanning and parsing | |
findstr "<stFnt:fontFamily>" %1>%init% | |
:: Second type of scanning and parsing | |
for /f "tokens=* delims= " %%f in ('findstr "FontFamily" %1') do ( | |
set line=%%f | |
call :Sp | |
) | |
type NUL > %clean% | |
:: DelDupeText.bat plus markup cleaning for 1st type of parsing | |
for /f "tokens=*" %%a in (%init%) do ( | |
set str=%%a | |
set str=!str:^<stFnt^:fontFamily^>=! | |
set str=!str:^</stFnt^:fontFamily^>=! | |
find /i ^"!str!^" %init% >nul | |
find /i ^"!str!^" %clean% >nul | |
if errorlevel 1 echo !str!>>%clean% | |
) | |
if exist %clean% del %init% | |
echo Searching for fonts to load from %fontdir% | |
echo; | |
for /f "tokens=*" %%x in (%clean%) do ( | |
set "x=%%x" | |
call :Sub x | |
) | |
del %clean% 2>nul | |
if exist "%fp%" (>nul findstr "^" "%fp%" || del "%fp%") | |
if exist "%fp%" ( | |
echo -------------- | |
echo; | |
pause | |
:: EDIT THIS LINE with the location of ShellTools FontLoader.exe | |
start %SystemRoot%\FontLoader.exe "%fp%" -load | |
echo Fonts loaded. | |
) | |
exit /b | |
:Unload | |
:: EDIT THIS LINE with the location of ShellTools FontLoader.exe | |
start %SystemRoot%\FontLoader.exe "%fp%" -unload -tmp | |
echo Fonts unloaded. | |
goto End | |
:Sub | |
dir /b %SystemRoot%\Fonts | find /i "!x!" >nul | |
if errorlevel 1 ( | |
dir /s /b %fontdir%\*.ttf,%fontdir%\*.otf | find /i "!x!">>"%fp%" | |
if errorlevel 1 ( | |
echo !x! was not found. | |
set /p x="Press Enter to skip or try a name variation: " | |
if NOT errorlevel 1 ( | |
call :Sub | |
goto :End | |
) else ( set "x=" ) | |
) | |
if NOT "!x!"=="" (echo Trying !x!) else (echo Skipped...) | |
) else ( | |
rem This one was found in Windows Fonts folder | |
) | |
goto :EOF | |
:Sp | |
for /f "tokens=1* delims=/)" %%a in ("%line%") do ( | |
echo "%%a" | find "FontFamily" >nul | |
if NOT errorlevel 1 ( | |
set "found=%%a" | |
set found=!found:FontFamily(=! | |
echo !found!>>%init% | |
) | |
set line=%%b | |
) | |
if not "%line%" == "" goto :Sp | |
goto :EOF | |
:End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depends on the Moon Software ShellTools executable FontLoader.exe !
What it does
It allows you to keep Windows installed fonts to a minimum by detecting fonts required by an Illustrator document and letting you load them temporarily. There are probably several apps that handle this, but this one is free, simple and lightweight.
The end goal for this batch file is to open old project files and have their missing fonts automagically loaded and unloaded.
Use case
I formatted my machine and thus lost all installed fonts. I didn't want to put them all back on from the backup because of the performance penalty and because I didn't need every font all the time. But I did want my old Illustrator projects to open correctly. So at the moment I keep my font collection on a separate drive, and run this batch script on the documents I want to open.
Usage
Run it again to unload the document fonts when you're done with it.
Known bugs
(Windows 7, Adobe Illustrator CS6)
To do
Maybe dispense with SendTo altogether and instead create a batch file to associate Illustrator project files with... that first checks for fonts, loads the missing ones and then passes the file on to Illustrator.exe