Photoshop CS JavaScript User Interface doesn't have a drop-down list control where a user can select a font from the available fonts. This JavaScript shows you how to implement this.
Save in a file named Choose a font.js
Code: Select all// Display choose font dialog box
var WindowPositionX = 100;
var WindowPositionY = 100;
var WindowWidth = 500;
var WindowHeight = 200;
//Create dialog box
var ChosenFontName
var ChosenFontPostScriptName
var bounds = {x:WindowPositionX ,y:WindowPositionX ,width:WindowWidth ,height:WindowHeight };
var dlg = new Window('dialog', 'Choose a font',bounds );
var uiButtonRun = "Close";
var bounds = {x:350,y:30,width:50 ,height:20 };
dlg.btnRun = dlg.add("button",bounds ,uiButtonRun );
dlg.btnRun.onClick = function() { this.parent.close(0); };
dlg.btnPnl = dlg.add('panel',[15,60,400,175], 'Choose a font');
var bounds = {x:25,y:25,width:150 ,height:20 };
//The scroll values range from zero to the length(count) of fonts on computer.
//The beginning value is set to zero.
var bounds = {x:25,y:50,width:350 ,height:20 };
dlg.btnPnl.widthScrl = dlg.btnPnl.add('scrollbar',bounds,0,0,app.fonts.length);
//The beginning font name is the first font in the font list
var bounds = {x:25,y:90,width:350 ,height:20 };
dlg.btnPnl.widthSt = dlg.btnPnl.add('statictext',bounds,app.fonts[0].name);
//Update the static text with the font name change from the scroll bar.
//The scroll bar value is used as a index into the fonts array.
//Save the current value for later use.
dlg.btnPnl.widthScrl.onChange =
function () {this.parent.widthSt.text = app.fonts[Math.round(this.value)].name;
ChosenFontName = app.fonts[Math.round(this.value)].name;
ChosenFontPostScriptName = app.fonts[Math.round(this.value)].postScriptName};
dlg.center();
dlg.show();
alert("Font name is " + ChosenFontName + "\n" + "Postscript name is "+ ChosenFontPostScriptName );
Photoshop CS JS User Interface choose a font from list
Photoshop CS JS User Interface choose a font from list
Thanks for that code and the excel font list one, you're an impressive ressource of scripting !
Photoshop CS JS User Interface choose a font from list
Thanks for the compliment. I wrote my first Fortran program in 1968, so I've been around for a while. I really do enjoy this stuff with Photoshop.
Larry
Larry