Modification to set ruler units to points, which is useful when working with type. This adds logic to set type size to an enumerated list of type sizes instead of simply rounding. You can comment out that block and use the simple round method if that works better. You can also change the list of sizes to suit.
/*
Utility Pack Scripts created by David M. Converse ©2018-24
This Photoshop script changes text layer sizes to the nearest integer
Last modifed 8/22/2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target photoshop
roundupTextSizes();
function roundupTextSizes(){
if(!app.documents.length > 0){ //must have an open document
return;
}
//initialize variables
var docRef = null;
var vis = true;
var LayerRef = null;
var TextRef = null;
var TextSize = 0;
var enumSizes = [8, 12, 16, 20, 24, 32, 36, 48, 60, 72];
try{
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
var originalRulerUnits = preferences.rulerUnits;
docRef = app.activeDocument;
preferences.rulerUnits = Units.POINTS;
docRef.activeLayer = docRef.artLayers[0];
for(var i = 0; i < docRef.artLayers.length; i++){ //loop through art layers
enumSizes = [8, 12, 16, 20, 24, 32, 36, 48, 60, 72] //reset list
LayerRef = docRef.artLayers[i];
vis = true;
if(LayerRef.kind == LayerKind.TEXT){
if(!LayerRef.visible){ //handle invisible layers
vis = false;
}
TextRef = LayerRef.textItem;
TextSize = TextRef.size; //get text size
//can use different logic here
//TextSize = Math.round(TextSize); //simple round down
//set size to enum value, comment block out and uncomment line above for simple rounding
enumSizes.push(TextSize); //add to enum array
enumSizes.sort(function(a,b){return a-b;}) //sort by value
for(var j = 0; j < enumSizes.length; j++){
if(j == enumSizes.length - 1){
TextRef.size = Math.round(TextSize); //larger than enum list, simple round down
break;
}
if(enumSizes[j] == TextSize){ //find current
TextRef.size = enumSizes[j + 1]; //change to next enum value
break;
}
}
//end set to enum value
if(vis == false){
LayerRef.visible = false; //reset to hidden as needed
}
}
}
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
}
catch(e){
Window.alert(e + e.line);
}
}