Copy link to clipboard
Copied
hi, so i've been trying to make a script that changes the text style based on it's contents (Whether if there's quote text or not) and making it into Bold Italic, regardless of what font I'm using, so I managed to make it change the text to faux italics, but when I try to make it to change the actual font style to the Italics version of the current font, it just doesnt work and I dunno what to do.
This is the main idea, get the text on quotes ("" or '') and change the text style of that to bold italic, or italic.
I was also trying to make it change the color of the text, so if the text layer is not black and has some color in it, change the quote text style and color to red, but I feel I wanna fix the main issue first.
I hope someone can help me out and thanks beforehand.
This is my current code
// Set Quote text in Bold Italic style
#target photoshop
function getAllTextLayers(parent) {
var layers = [];
for (var i = 0; i < parent.layers.length; i++) {
var layer = parent.layers[i];
if (layer.typename === "ArtLayer" && layer.kind === LayerKind.TEXT) {
layers.push(layer);
} else if (layer.typename === "LayerSet") {
layers = layers.concat(getAllTextLayers(layer));
}
}
return layers;
}
function changeQuotedTextToItalic(textLayer) {
var text = textLayer.textItem.contents;
var quoteRegex = /"([^"]*)"/g;
var matches = [];
var match;
while ((match = quoteRegex.exec(text)) !== null) {
matches.push({
start: match.index + 1,
end: match.index + match[0].length - 1
});
}
if (matches.length === 0) return;
// Get ActionDescriptor for the active text layer
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("TxLr"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var layerDesc = executeActionGet(ref);
var textDesc = layerDesc.getObjectValue(stringIDToTypeID("textKey"));
var styleRanges = textDesc.getList(stringIDToTypeID("textStyleRange"));
// Apply italic to matched ranges
for (var m = 0; m < matches.length; m++) {
var start = matches[m].start;
var end = matches[m].end;
// Find a style range that covers this range
for (var i = 0; i < styleRanges.count; i++) {
var rangeDesc = styleRanges.getObjectValue(i);
var rStart = rangeDesc.getInteger(stringIDToTypeID("from"));
var rEnd = rangeDesc.getInteger(stringIDToTypeID("to"));
if (start >= rStart && end <= rEnd) {
// Clone the existing style descriptor
var styleDesc = rangeDesc.getObjectValue(stringIDToTypeID("textStyle"));
// Add faux italic
styleDesc.putBoolean(stringIDToTypeID("syntheticItalic"), true);
// Create new range descriptor
var newRange = new ActionDescriptor();
newRange.putInteger(stringIDToTypeID("from"), start);
newRange.putInteger(stringIDToTypeID("to"), end);
newRange.putObject(stringIDToTypeID("textStyle"), stringIDToTypeID("textStyle"), styleDesc);
styleRanges.putObject(stringIDToTypeID("textStyleRange"), newRange);
break;
}
}
}
// Put modified style ranges back
textDesc.putList(stringIDToTypeID("textStyleRange"), styleRanges);
// Apply changes
var setRef = new ActionReference();
setRef.putEnumerated(charIDToTypeID("TxLr"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var setDesc = new ActionDescriptor();
setDesc.putReference(charIDToTypeID("null"), setRef);
setDesc.putObject(charIDToTypeID("T "), charIDToTypeID("TxLr"), textDesc);
executeAction(charIDToTypeID("setd"), setDesc, DialogModes.NO);
}
// Main loop
if (app.documents.length > 0) {
var doc = app.activeDocument;
var textLayers = getAllTextLayers(doc);
for (var i = 0; i < textLayers.length; i++) {
doc.activeLayer = textLayers[i];
changeQuotedTextToItalic(textLayers[i]);
}
alert("Italic applied to all quoted text.");
}
Okay so I kinda gave up on that, but I decided to throw a shot with the new GPT-5 and I was amazed on how good it's on coding.
So now it does exactly what I wanted, using regex it detects any text that's on quotes, single quotes and even the curly ones and replaces the text in the quotes to a Bold Italic style.
It works in the current layer (Or layers since it supports multilayer)
And it also has a function I've been dreaming about for YEARS, it detects if the text is not black or white and if th
Copy link to clipboard
Copied
Hi, @Iuigidesu ! Your code works.
Change the line:
setDesc.putObject(charIDToTypeID("T "), charIDToTypeID("TxLr"), textDesc);
to:
setDesc.putObject(charIDToTypeID("T "), charIDToTypeID("TxLr"), textDesc);
(pay attention to the number of spaces - charIDToTypeID gets a key that must necessarily consist of 4 characters)
* note that there are many quote codes (this may not be the best symbol to identify the place of style replacement). At least, make sure that the script uses exactly the same type of quotes that are present in the text layer.
Copy link to clipboard
Copied
Okay so I kinda gave up on that, but I decided to throw a shot with the new GPT-5 and I was amazed on how good it's on coding.
So now it does exactly what I wanted, using regex it detects any text that's on quotes, single quotes and even the curly ones and replaces the text in the quotes to a Bold Italic style.
It works in the current layer (Or layers since it supports multilayer)
And it also has a function I've been dreaming about for YEARS, it detects if the text is not black or white and if the mode of the document is RGB, and if so, it not only changes the style but the color as well.
I'm really amazed with the whole AI thing.
I still gotta do manual adjustments, but the script is pretty much good to go.
I'll leave some screenshots and I can share the script if someone wants it, just once i'm done with it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now