Selection Basics
To make a selection you must define a shape. To make a rectangular selection you should define the corners in the order shown below.

Select and Paste
The below code selects the proper rectangular area on the active document which is now "PSA TypoTiler". We use two variables to properly make the selections. "horizontal" is the current row, vertical is the current "column". If "horizontal" reaches the number of columns it is set to 0 and "1" is add to "vertical", it means we are at the first cell of the second row. After the selection is made the copied image of the glyph is pasted.
var shapeRef = [
[(horizontal*blockwidth),(vertical*blockheight)],
[((horizontal*blockwidth)+blockwidth),(vertical*blockheight)],
[((horizontal*blockwidth)+blockwidth),((vertical*blockheight)+blockheight)],
[(horizontal*blockwidth),((vertical*blockheight)+blockheight)]
]
app.activeDocument.selection.select(shapeRef)
horizontal= horizontal+1 ;
app.activeDocument.paste();
if(horizontal == columns) {
//end of a column, move to the next one
vertical = vertical+1;
//reset the horizontal
horizontal = 0;
}
}
}
How it Works
Below image can explain how the above code can make selections. The loop is repeated until the last letter of the input text is placed.

Finalize the Script
Finally add these lines at the end of your code if you didn’t. This will center the dialog and make it visible. Now save the code as "PSA-TypoTiler.jsx" into "PSA-TypoTiler" folder.
dlg.center();
dlg.show();
Here is the complete code:
app.preferences.rulerUnits = Units.PIXELS;
var rows;
var blockwidth = 300;
var blockheight = 300;
var columns = 3;
var horizontal = 0;
var vertical = 0;
//Create new dialog
var dlg = new Window(‘dialog’,‘PsAwesome-TypoTiler-v1.0′);
//Add a Panel to contain a Scrollbar and a Text Field
dlg.sizePnl = dlg.add(‘panel’, [0,0,340,60], ‘Set Mosaic Width [# of Cells]‘);
dlg.sizePnl.widthSt = dlg.sizePnl.add(‘statictext’, [15,15,65,35], ‘Width:’);
dlg.sizePnl.widthScrl = dlg.sizePnl.add(‘scrollbar’, [75,15,195,35], 3, 1, 16);
dlg.sizePnl.widthEt = dlg.sizePnl.add(‘edittext’, [205,15,245,35]);
dlg.sizePnl.widthEt.enabled=false;
dlg.sizePnl.widthEt.text=dlg.sizePnl.widthScrl.value;
dlg.sizePnl.widthScrl.onChanging = function(){
dlg.sizePnl.widthEt.text=Math.floor(this.value);
columns=Math.floor(this.value);
}
//Add a Panel to contain input text
dlg.textPnl = dlg.add(‘panel’, [0,0,340,130], ‘Enter Text’);
dlg.textPnl.msgEt = dlg.textPnl.add(‘edittext’, [20,20,315,105], ”,{multiline:true});
//Add a Group to contain Buttons
dlg.buttons = dlg.add(‘group’);
dlg.buttons.orientation=‘row’;
dlg.buttons.bu1 = dlg.buttons.add(‘button’,undefined,‘GO’);
dlg.buttons.bu2 = dlg.buttons.add(‘button’,undefined,‘Cancel’);
//Add a Function to be triggered on button click
dlg.buttons.bu1.onClick = function(){
dlg.close();
var textt=dlg.textPnl.msgEt.text;
//Calculate the grid
if ((textt.length/columns)>Math.floor(textt.length/columns)) {
rows = Math.floor(textt.length/columns)+1;
} else {
rows = Math.floor(textt.length/columns);
}
var wd= blockwidth*columns;
var hg= blockheight*rows;
// create a new document
var psaDoc = app.documents.add(wd, hg, 300, "PSA TypoTiler");
//Open glyph copy
for (var i = 0; i<textt.length; i++) {
var fname = textt.charAt(i)+‘.JPG’;
if (textt.charAt(i)==" "){
fname = ‘space.JPG’;
}
var glyphToOpen = File("c:/PSA-TypoTiler/" + fname)
open(glyphToOpen)
var layerRef = app.activeDocument.artLayers.getByName("Background");
app.activeDocument.selection.selectAll();
app.activeDocument.selection.copy();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//Make the proper selection
var shapeRef = [
[(horizontal*blockwidth),(vertical*blockheight)],
[((horizontal*blockwidth)+blockwidth),(vertical*blockheight)],
[((horizontal*blockwidth)+blockwidth),((vertical*blockheight)+blockheight)],
[(horizontal*blockwidth),((vertical*blockheight)+blockheight)]
]
app.activeDocument.selection.select(shapeRef)
horizontal= horizontal+1 ;
app.activeDocument.paste();
if(horizontal == columns) {
//end of a column, move to the next one
vertical = vertical+1;
//reset the horizontal
horizontal = 0;
}
}
}
//Center and show dialog
dlg.center();
dlg.show();
Run the Script
Start Photoshop. Go to File > Scripts > Browse and select the "PSA-TypoTiler.jsx". You’ll see the dialogbox, leave width at 3, enter the text "awe some " and hit go.

Congratulations
Here is the final image i had using the PSA TypoTiler script. I hope you liked this tutorial, had fun making it and i hope it will become handy.

page 1 page 2































I really liked this tutorial, Eren. I hope I will find some more tutorials in your website on Scripting in Photoshop.
Useful Tutorial
nice decoration
Excellent work, Keep it like this!
Lovely. I really like this tutorial. Thanks for sharing.