Fonts - ff6347/extendscript GitHub Wiki
###fonts
/**
* Fonts can be a pain in the ***.
* You can call them by name, but then you have to be very precise
* by writing their name in the script.
* An easier way is to call them by number
* but there you will face problems when you activate or deactivate fonts
* because their numbers will change.
*
* This script writes a list of all available fonts
* on your system to the desktop.
* Have a look into new file.
* The weight is separated by a TAB.
* If you want to call a font by the name
* you have to write that TAB.
* Some IDEs translate the TAB character into four white spaces
* so be careful.
*
*/
main(); // main everything is in here
function main(){
var list = new Array(); // a list
// loop through the fonts and add their info in a list
for (var i = 0; i < app.fonts.length;i++){
list.push("app.fonts.item("+ String(i) +") --> " +app.fonts[i].name);
}; // end loop
// get the text file
var txtFile = File("~/Desktop/id_fontslist.txt");
if(!txtFile.exists){
// If the file does not exist create one.
txtFile = new File("~/Desktop/id_fontslist.txt");
}else{
// If it exists, ask the user if it should be overwritten.
var res = confirm ("The file already exists. Should I overwrite it?", true, "titleWINonly");
// If the user hits "no" stop the script.
if(res != true){
return;
};
};
var out; // Our output.
// We know already that the file exists
// but to be sure...
if( txtFile!='' ){
//Open the file for writing.
out = txtFile.open( 'e', undefined, undefined );
txtFile.encoding = "UTF-8";
txtFile.lineFeed = "Unix"; //convert to UNIX lineFeed
// txtFile.lineFeed = "Windows";
// txtFile.lineFeed = "Macintosh";
};
// got an output?
if( out != false ){
// loop the list and write each item to the file
for(var i in list){
txtFile.writeln(list[i]);
};
// always close files!
txtFile.close();
txtFile.execute();
};
// This is more the C or C++ style
// but it is good for the console.
// We know everything went fine.
return 0;
};