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>
6.3 KiB
Adobe Photoshop Text Extraction Scripts for macOS
This repository contains Python and JavaScript scripts specifically optimized for macOS to extract text from Adobe Photoshop PSD files without requiring any Windows-based dependencies.
Overview
The scripts provide a way to automatically extract text layers from PSD files, preserving all formatting, line breaks, and styles. They're designed to work with:
- Adobe Photoshop on macOS (2024/2025/CC versions)
- Python 3.x
- Files with spaces in their names
- Batch processing of many PSD files
- Support for files with or without text layers
Requirements
- macOS (tested on 10.15 and later)
- Adobe Photoshop (installed in the Applications folder)
- Python 3.6 or later
Installation
Option 1: Use with system Python
- Clone or download this repository
- Ensure you have Python 3.x installed on your Mac (verify with
python3 --version) - No additional packages needed - the scripts use only standard library modules
Option 2: Create a virtual environment (recommended)
# Navigate to the script directory
cd /path/to/Adobe-PS-scripts
# Create a virtual environment
python3 -m venv ./venv
# Activate the virtual environment
source ./venv/bin/activate
# When finished, deactivate the environment
deactivate
Script Files
The package includes these main files:
mac_ps_extract.py- The main Python script for extracting text from PSD filesExtractTextWithBreaks.jsx- The JavaScript (ExtendScript) code that runs within Photoshopbatch_extract_text.py- A helper script for batch processing (optional)
Usage
Basic Usage
The simplest way to extract text from PSD files:
python3 mac_ps_extract.py /path/to/psd_files
This will:
- Process all PSD files in the specified directory
- Save JSON files with extracted text next to each PSD file
- Naming format will be:
[original-filename]-textonly.json
Advanced Options
python3 mac_ps_extract.py /path/to/psd_files --output-dir /path/for/output --recursive --verbose
Command Line Arguments
| Argument | Short | Description |
|---|---|---|
--output-dir |
-o |
Directory to save extracted JSON files (defaults to same as PSD) |
--recursive |
-r |
Search for PSD files in subdirectories |
--verbose |
-v |
Enable detailed logging for troubleshooting |
Examples
Extract text from all PSD files in the current directory:
python3 mac_ps_extract.py .
Extract text from a specific directory and save to another location:
python3 mac_ps_extract.py /Users/username/Desktop/PSD_Files -o /Users/username/Desktop/Extracted_Text
Process files recursively with verbose logging:
python3 mac_ps_extract.py /Users/username/Projects/Assets -r -v
Output Format
The script produces JSON files with this structure:
{
"documentName": "example.psd",
"psdPath": "/path/to/example.psd",
"extractedAt": "2025-03-18 09:00:00",
"dimensions": {
"width": 1920,
"height": 1080
},
"textLayerCount": 2,
"textLayers": [
{
"id": "",
"name": "Heading",
"path": "Heading",
"text": "This is a heading",
"updatedText": "This is a heading",
"visible": true,
"styleInfo": {
"font": "Arial-Bold",
"size": 24,
"color": null,
"alignment": "left",
"styles": [
{
"start": 0,
"end": 16,
"text": "This is a heading",
"font": "Arial-Bold",
"style": "Bold",
"size": 24
}
]
},
"hasRichTextFormatting": false
},
// Additional text layers...
]
}
If a PSD file contains no text layers, an empty JSON file is still created with basic document information.
How It Works
The system uses a combination of:
- AppleScript to communicate with Adobe Photoshop
- ExtendScript (JSX) to execute code inside Photoshop
- Python to coordinate the process and handle file operations
The process flow is:
- Python script locates PSD files to process
- For each file, it uses AppleScript to open the PSD in Photoshop
- It then runs the JSX script inside Photoshop to extract text
- The extracted text is saved as a JSON file
- Photoshop closes the document and moves to the next file
Troubleshooting
Common Issues
Script fails to find Photoshop:
- Ensure Photoshop is installed in the Applications folder
- The script looks for common Photoshop versions; you may need to update the
_find_photoshopmethod if you have a different version
Error opening files with spaces:
- The script handles spaces in filenames, but if you're having trouble, avoid spaces in file/folder names
No text extracted:
- Some PSD files may not contain any text layers
- The script will create an empty JSON file with document info
Script is taking too long:
- Processing large PSD files can be time-consuming
- Try processing fewer files at once
Verbose Logging
Run with the -v or --verbose flag to see detailed logs:
python3 mac_ps_extract.py /path/to/psd_files -v
The logs show:
- Photoshop detection and communication
- File opening and processing steps
- Text extraction details
- Error messages and warnings
Limitations
- Works only on macOS with Photoshop installed
- Requires Photoshop to be closed or not actively editing files being processed
- Does not support modification of text layers (extraction only)
- Large files with many text layers can take time to process
Advanced Customization
If you need to modify how text is extracted, you can edit:
ExtractTextWithBreaks.jsxto change how text and formatting is extracted from Photoshopmac_ps_extract.pyto modify file handling, AppleScript communication, or output format
License
This project is available under the MIT License.
Credits
Developed for efficient text extraction from Adobe Photoshop files on macOS, with special focus on handling multilingual text content and preserving formatting.
Questions and Support
For issues, questions, or contributions:
- Check the detailed logs with verbose mode (
-v) to identify the issue - Ensure you're using a supported Photoshop version
- Create an issue in the repository with:
- Your macOS version
- Your Photoshop version
- Command you ran
- Any error messages from verbose output