Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Photoshop Script to Set Italic Font Style?

Explorer ,
Aug 09, 2025 Aug 09, 2025

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.

Iuigidesu_0-1754760994518.png

Iuigidesu_1-1754761045876.pngIuigidesu_2-1754761074853.png

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.");
}




TOPICS
Actions and scripting
258
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Aug 11, 2025 Aug 11, 2025

 

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

...
Translate
Adobe
Mentor ,
Aug 09, 2025 Aug 09, 2025

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.

 

 

 

 
 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 11, 2025 Aug 11, 2025
LATEST

 

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.

Iuigidesu_0-1754972907991.png

Iuigidesu_1-1754972952226.png

Iuigidesu_2-1754973279064.png

Iuigidesu_3-1754973314741.png

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines