Rename for Adobe Photoshop Artboards

Sometimes the pace of work is so high that it is necessary to automate small processes. The fact that designing goes to different dimensions in different programmes can sometimes make things difficult. Since the Artboard working style entered our lives, it provides great efficiency in multiple dimensions. But you may encounter a problem in the output of the work. File names? Oops!

How?

Very simply, the script can offer this process very easily. The working logic is as follows:

  1. Save the following script in ".jsx" format

  2. Run the script in Adobe Photoshop

  3. The names of the artboards will be edited as follows: "Artboard size _ File name"

Size only?

Yes, if you want only "Artboard size" to be written on the artboards, change this code.

artboard[i].name = artboardWidth+'x'+artboardHeight;

Code

#target photoshop
//#include json2.js

var doc = app.activeDocument;
var targetPath = new File($.fileName);
var logFile = new File(targetPath.path + '/log.txt');

logFile.encoding = 'UTF8';
if (logFile.exists)
	logFile.remove();
logFile.open('w');
log('Log file created.', logFile);

var savePath = targetPath.path+'/Examples';
var saveName = doc.name.replace('.psd','');

var newpath = targetPath.fsName;
newpath = newpath.replace('\renameArtboards.jsx','');

var artboard = doc.layerSets;

for (var i = 0; i < artboard.length; i++) {

    var prop = stringIDToTypeID("bounds");
    var r = new ActionReference();    
    r.putProperty(stringIDToTypeID("property"), prop);
    r.putIdentifier(stringIDToTypeID("layer"), artboard[i].id);
    var d = executeActionGet(r).getObjectValue(prop);
    var bounds = new Array();
    bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));  
    bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top"));  
    bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
    bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));

    artboardWidth = bounds[2] - bounds[0];  
    artboardHeight = bounds[3] - bounds[1];

    // artboard[i].name = 'Artboard '+i;

    var gcd = gcd_rec(artboardWidth,artboardHeight);

    var ratio = new Array();
    ratio[0] = artboardWidth/gcd;
    ratio[1] = artboardHeight/gcd;

    // log(artboardWidth+':'+artboardHeight, logFile)
    // log(ratio[0]+':'+ratio[1], logFile)

    artboard[i].name = artboardWidth+'x'+artboardHeight+'_'+doc.name.replace('.psd','');

}

function gcd_rec(a, b) {
    if (b) {
        return gcd_rec(b, a % b);
    } else {
        return Math.abs(a);
    }
}


function loadJson(relPath){
	var script = new File($.fileName);
	var jsonFile = new File(script.path + '/' + relPath);
	jsonFile.open('r');
	var str = jsonFile.read();
	jsonFile.close();
	log('JSON File Read.', logFile);
	return JSON.parse(str);
}

function log(message, file){
	var time = new Date();
	file.write(('0' + time.getHours()).slice(-2) + ':' + ('0' + time.getMinutes()).slice(-2) + ':' + ('0' + time.getSeconds()).slice(-2));
	file.write('  >>>>> ' + message);
	file.writeln('');
}

date published

May 10, 2024

date published

May 10, 2024

date published

May 10, 2024

date published

May 10, 2024

reading time

5 min

reading time

5 min

reading time

5 min

reading time

5 min

.say hello

i'm open for freelance projects, feel free to email me to see how can we collaborate

.say hello

i'm open for freelance projects, feel free to email me to see how can we collaborate

.say hello

i'm open for freelance projects, feel free to email me to see how can we collaborate

.say hello

i'm open for freelance projects, feel free to email me to see how can we collaborate