Local and cloud-based workflows for extracting and updating text layers in PSD files via ExtendScript and Adobe PS API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
13 KiB
Text Layer Update Workflow Example
This document provides a step-by-step walkthrough of using the local script workflow to extract and update text in PSD files.
Example Scenario
In this example, we'll update the text in a product marketing PSD file:
- Extract text from a Vichy product PSD
- Modify the product description text
- Update the PSD with the new text
- Verify the changes
Step 1: Extract Text from PSD
First, we'll extract the current text from the Vichy product PSD file:
python mac_ps_extract.py TESTFILES/BATCH-UPDATES/
This will create JSON files with the -textonly.json suffix next to each PSD file:
Successfully processed 6 of 6 PSD files.
JSON files saved next to their PSD files
Let's examine one of the extracted JSON files:
cat TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients-textonly.json
The output will show the text layer content:
{
"documentName": "Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients.psd",
"psdPath": "/Users/daveporter/Desktop/CODING-2024/Adobe-API-PS-scripts/TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients.psd",
"extractedAt": "Mon Apr 22 2025 15:12:27",
"dimensions": {
"width": 1200,
"height": 800
},
"textLayerCount": 2,
"textLayers": [
{
"id": "",
"name": "Key Ingredients",
"path": "Key Ingredients",
"text": "KEY INGREDIENTS",
"updatedText": "KEY INGREDIENTS",
"visible": true,
"styleInfo": {
"font": "Arial-Bold",
"size": 24,
"color": null,
"alignment": "left",
"styles": [
{
"start": 0,
"end": 15,
"text": "KEY INGREDIENTS",
"font": "Arial-Bold",
"style": "Bold",
"size": 24
}
]
},
"hasRichTextFormatting": false
},
{
"id": "",
"name": "Ingredient List",
"path": "Ingredient List",
"text": "• VITAMIN C: Brightens skin and provides antioxidant protection\n• HYALURONIC ACID: Hydrates and plumps skin with moisture\n• NIACINAMIDE: Reduces appearance of pores and evens skin tone\n• PEPTIDES: Support collagen production for firmer skin\n• GLYCERIN: Attracts moisture to keep skin hydrated\n• VICHY VOLCANIC WATER: Rich in minerals to strengthen skin",
"updatedText": "• VITAMIN C: Brightens skin and provides antioxidant protection\n• HYALURONIC ACID: Hydrates and plumps skin with moisture\n• NIACINAMIDE: Reduces appearance of pores and evens skin tone\n• PEPTIDES: Support collagen production for firmer skin\n• GLYCERIN: Attracts moisture to keep skin hydrated\n• VICHY VOLCANIC WATER: Rich in minerals to strengthen skin",
"visible": true,
"styleInfo": {
"font": "Arial",
"size": 14,
"color": null,
"alignment": "left",
"styles": [
{
"start": 0,
"end": 11,
"text": "• VITAMIN C",
"font": "Arial-Bold",
"style": "Bold",
"size": 14
},
{
"start": 12,
"end": 59,
"text": ": Brightens skin and provides antioxidant protection",
"font": "Arial",
"style": "Regular",
"size": 14
},
{
"start": 60,
"end": 76,
"text": "• HYALURONIC ACID",
"font": "Arial-Bold",
"style": "Bold",
"size": 14
},
{
"start": 77,
"end": 114,
"text": ": Hydrates and plumps skin with moisture",
"font": "Arial",
"style": "Regular",
"size": 14
},
{
"start": 115,
"end": 128,
"text": "• NIACINAMIDE",
"font": "Arial-Bold",
"style": "Bold",
"size": 14
},
{
"start": 129,
"end": 174,
"text": ": Reduces appearance of pores and evens skin tone",
"font": "Arial",
"style": "Regular",
"size": 14
},
{
"start": 175,
"end": 185,
"text": "• PEPTIDES",
"font": "Arial-Bold",
"style": "Bold",
"size": 14
},
{
"start": 186,
"end": 227,
"text": ": Support collagen production for firmer skin",
"font": "Arial",
"style": "Regular",
"size": 14
},
{
"start": 228,
"end": 238,
"text": "• GLYCERIN",
"font": "Arial-Bold",
"style": "Bold",
"size": 14
},
{
"start": 239,
"end": 276,
"text": ": Attracts moisture to keep skin hydrated",
"font": "Arial",
"style": "Regular",
"size": 14
},
{
"start": 277,
"end": 297,
"text": "• VICHY VOLCANIC WATER",
"font": "Arial-Bold",
"style": "Bold",
"size": 14
},
{
"start": 298,
"end": 342,
"text": ": Rich in minerals to strengthen skin",
"font": "Arial",
"style": "Regular",
"size": 14
}
]
},
"hasRichTextFormatting": true
}
]
}
Step 2: Modify the JSON
Now let's edit the JSON file to update the ingredient list. We'll add a new ingredient and modify the description of an existing one:
# Copy to a new file to preserve the original
cp TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients-textonly.json TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients-textonly-updated.json
Edit the copied file with your preferred text editor, and modify the "updatedText" field for the "Ingredient List" layer:
"updatedText": "• VITAMIN C: Brightens skin and provides antioxidant protection\n• HYALURONIC ACID: Provides intense hydration and plumps skin with long-lasting moisture\n• NIACINAMIDE: Reduces appearance of pores and evens skin tone\n• PEPTIDES: Support collagen production for firmer skin\n• GLYCERIN: Attracts moisture to keep skin hydrated\n• VICHY VOLCANIC WATER: Rich in 15 minerals to strengthen skin barrier\n• COLLAGEN PEPTIDES: Helps restore skin's natural bounce and elasticity",
Key changes made:
- Enhanced description for HYALURONIC ACID
- Added specificity about mineral count in VICHY VOLCANIC WATER
- Added a new ingredient: COLLAGEN PEPTIDES
Step 3: Update the PSD
First, let's do a dry run to verify the changes would be applied correctly:
python mac_ps_update.py TESTFILES/BATCH-UPDATES/ --dry-run
Output:
DRY RUN MODE: Changes will be previewed but not applied.
Found 7 JSON files that would be processed:
MATCH: Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients-textonly-updated.json → Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients.psd
MATCH: Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Clinical Results-textonly.json → Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Clinical Results.psd
MATCH: Vichy-Product-Skincare-Liftactiv -Collagen 16 Bonding Serum -30ml-3337875912600-Routine-textonly.json → Vichy-Product-Skincare-Liftactiv -Collagen 16 Bonding Serum -30ml-3337875912600-Routine.psd
MATCH: Vichy-Product-Skincare-Liftactiv -Collagen 16 Bonding Serum -30ml-3337875912600-Safety-textonly.json → Vichy-Product-Skincare-Liftactiv -Collagen 16 Bonding Serum -30ml-3337875912600-Safety.psd
MATCH: Vichy-Product-Skincare-Liftactiv -Collagen 16 Bonding Serum -30ml-3337875912600-Texture-textonly.json → Vichy-Product-Skincare-Liftactiv -Collagen 16 Bonding Serum -30ml-3337875912600-Texture.psd
MATCH: Vichy-Product-Skincare-Liftactiv-Collagen 16 Bonding Serum -30ml-3337875912600-Packshot-texture-textonly.json → Vichy-Product-Skincare-Liftactiv-Collagen 16 Bonding Serum -30ml-3337875912600-Packshot-texture.psd
MATCH: Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Professional Endorsement-textonly.json → Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Professional Endorsement.psd
Dry run complete. No changes were made to PSD files.
Now let's run the update with just our edited file, and save the changes:
python mac_ps_update.py TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients-textonly-updated.json -s
Output:
Processing JSON files from: TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients-textonly-updated.json
Looking for PSD files in: TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients-textonly-updated.json
Found matching PSD based on documentName: Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients.psd
Found Photoshop at: /Applications/Adobe Photoshop 2025/Adobe Photoshop 2025.app
Photoshop (Adobe Photoshop 2025) launched successfully
Opened file: /Users/daveporter/Desktop/CODING-2024/Adobe-API-PS-scripts/TESTFILES/BATCH-UPDATES/Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients.psd
JSX script executed successfully
Closed document (save=True)
Successfully updated text in Vichy-Product-Skincare-Liftactiv-Collagen-16-Bonding-Serum-30ml-3337875912600-Ingredients.psd and saved changes
Update complete:
Successfully processed: 1 of 1 files
Changes have been saved to PSD files
Step 4: Verify the Changes
Open the updated PSD file in Photoshop to verify that:
- The HYALURONIC ACID description now shows "Provides intense hydration and plumps skin with long-lasting moisture"
- The VICHY VOLCANIC WATER description includes "15 minerals"
- The new COLLAGEN PEPTIDES ingredient appears at the end of the list
- All text formatting (bold for ingredient names, regular for descriptions) was preserved
Additional Examples
Batch Processing Multiple Files
To update multiple files at once:
# Extract text from all PSDs in a directory
python mac_ps_extract.py /path/to/psd_directory
# Edit the JSON files as needed
# Update all PSDs with a dry run first
python mac_ps_update.py /path/to/json_directory --dry-run
# Apply and save the changes
python mac_ps_update.py /path/to/json_directory --save
Working with Complex Text Formatting
When working with complex text that has multiple formatting styles:
- The
mac_ps_extract.pyscript preserves detailed formatting information in the "styles" array - This includes font, style (Bold, Regular, etc.), size, and character ranges
- When updating,
mac_ps_update.pywill attempt to preserve this formatting - For best results with complex formatting:
- Try to keep the same general structure of paragraphs
- Don't change the order of specially formatted sections
- When adding new text, follow similar patterns to existing text
Common Issues and Solutions
Text Layer Not Found
Problem: Script reports "Layer not found" despite being visible in Photoshop
Solution:
- Ensure the layer name in the JSON exactly matches the layer name in Photoshop
- Check for hidden spaces or special characters in layer names
- Verify the layer isn't inside a hidden group
Formatting Lost After Update
Problem: Bold or italic formatting is lost after updating text
Solution:
- Check if the layer has
"hasRichTextFormatting": truein the JSON - Review the "styles" array for proper formatting information
- Try keeping the text structure similar to the original
- For complex formatting, consider making smaller incremental changes
Photoshop Not Launching
Problem: Script can't find or launch Photoshop
Solution:
- Launch Photoshop manually before running the script
- Check the path in the script matches your Photoshop installation
- Ensure you have granted necessary permissions to terminal/scripts
Best Practices
- Always make backups before batch updating PSD files
- Use dry-run mode before applying changes with
--save - Keep text structure similar when making updates to preserve formatting
- Check layer names in the extracted JSON match the PSD exactly
- Use absolute paths when specifying directories with spaces
- Close Photoshop documents before running scripts to avoid conflicts
- Monitor memory usage when batch processing large files