• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Any JavaScript experts here? or Photoshop

Graphic46

Active member
Oct 2, 2018
422
100
28
Hi all !
I need a script that will write all the letters one by one on the blank background and save it. I searched the internet and found this below code. it numbers one by one to any number. but I need A to Z letter.

how to change code for to sort alphabetically ?
so this code export images = #1 #2 #3 #4 #5 ...
but i need A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

can someone help me? thanks.

JavaScript:
function main() {

//this just checks if you have a text layer selected
try {
    var textLayer = activeDocument.activeLayer.textItem
} catch (e) {
    alert("active layer isn't a text layer");
    return
};

// PNG save options to use below, using defaults
var pngOpts = new PNGSaveOptions();
pngOpts.compression = 1;
pngOpts.interlaced = false;

var loops = 5,
    outputFolder = Folder.selectDialog('', Folder.desktop); //this will ask for an output folder

for (var i = 0; i < loops; i++) {
    var myNum = i + 1;
    textLayer.contents = "#" + myNum; //this will change layer contents to number only. if you need some text here, write it in quotes like textLayer.contents = "my text" + myNum;
    activeDocument.saveAs(new File(outputFolder + "/#" + myNum + ".png"), pngOpts, true, Extension.LOWERCASE);
}

}
app.activeDocument.suspendHistory("temp", "main()");
 
I think the following might help you.

The charcode for letter capital A = 65, B = 66, C = 67 and so on. So, you change the base number from 0 to 64 and then convert the incrementing number to the letter with String.fromCharCode which results in this code (only the 'for' section from your example):

JavaScript:
for (var i = 64; i < loops; i++) {
    var myNum = i + 1;
    var myLetter = String.fromCharCode(myNum);
    textLayer.contents = "#" + myLetter; //this will change layer contents to LETTER only. if you need some text here, write it in quotes like textLayer.contents = "my text" + myLetter;
    activeDocument.saveAs(new File(outputFolder + "/#" + myLetter + ".png"), pngOpts, true, Extension.LOWERCASE);
}

Hope this helps, please let me know.

EDIT: this of course results in #A, #B a.s.o. You probably don't want that so just leave that hash character out or replace with anything you want there.
 
Last edited:
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock