Automating Photoshop Mockups with Smart Objects

Design mockups in Photoshop can be time-consuming, especially if you are working on several designs that require frequent updates. This became a personal challenge for me while creating a template where I wrote an automated Photoshop script to replace Smart Object layers with specific PDF pages instead.
Introduction
This blog walks through the process of creating this automation, the obstacles faced, and the solutions that made it a success.
The Challenge
The goal was to automate the placement of specific pages from a PDF into Smart Object layers within a Photoshop mockup file (PSD). The workflow needed to:
✔️ Select specific pages from a multi-page PDF ✔️ Replace the Smart Object layers within the PSD ✔️ Ensure the new content was properly resized and positioned ✔️ Save the final mockup as a high-quality JPG
Manually handling these tasks for multiple designs would be tedious and error-prone, making automation a perfect solution.
Step 1: Understanding Smart Object Replacement
Photoshop allows Smart Object layers to be dynamically edited using scripts. The key function in our script was:
function openSmartObject(layer) {
app.activeDocument.activeLayer = layer;
executeAction(stringIDToTypeID("placedLayerEditContents"), undefined, DialogModes.NO);
}
This ensured that I could open and modify Smart Objects programmatically, which was essential for replacing their content.
Step 2: Extracting and Pasting the PDF Content
I needed to open a specific page from a multi-page PDF, select its content, copy it, and paste it into the Smart Object layer. Our solution:
var pdfOptions = new PDFOpenOptions();
pdfOptions.page = pageNumber - 1; // Pages are zero-indexed in Photoshop
var pdfPage = app.open(pdfFile, pdfOptions);
pdfPage.selection.selectAll();
pdfPage.selection.copy();
pdfPage.close(SaveOptions.DONOTSAVECHANGES);
This ensured that the correct page was opened and copied, preventing the wrong content from being pasted.
Step 3: Resizing the Pasted Content to Fit the Smart Object
One of the biggest challenges was ensuring that the pasted PDF page scaled correctly to match the Smart Object’s bounding box. Initially, the pasted content wasn’t filling the space properly, leading to unwanted gaps.
The solution was to dynamically adjust the scaling based on the target size (2400×3300 pixels at 300 DPI):
pastedLayer.resize(100, 100, AnchorPosition.TOPLEFT);
var targetWidth = 2400;
var targetHeight = 3300;
var layerWidth = pastedLayer.bounds[2] - pastedLayer.bounds[0];
var layerHeight = pastedLayer.bounds[3] - pastedLayer.bounds[1];
pastedLayer.resize((targetWidth / layerWidth) * 100, (targetHeight / layerHeight) * 100, AnchorPosition.MIDDLECENTER);
This adjustment automatically scaled and centered the content, ensuring it completely filled the Smart Object.
Step 4: Saving the Final Output as a JPG
Originally, the script saved the final mockup as a PNG, but we later modified it to save as a high-quality JPG:
var saveOptions = new JPEGSaveOptions();
saveOptions.quality = 12; // Maximum quality
mockupDoc.saveAs(outputFile, saveOptions, true, Extension.LOWERCASE);
This change allowed for smaller file sizes while maintaining high visual quality.
Final Result & Key Takeaways
After several iterations, we successfully created a fully automated Photoshop script that:
✔️ Opens a mockup PSD file ✔️ Replaces Smart Object layers with specific PDF pages ✔️ Resizes and positions the content correctly ✔️ Saves the final mockup as a high-quality JPG
This workflow significantly reduces manual effort, eliminates errors, and speeds up the process of updating Photoshop mockups.
Conclusion
By leveraging Photoshop scripting, I was able to build an efficient automation tool that saves hours of repetitive work. Whether you’re working with product packaging, marketing materials, or design templates, automating Smart Object replacements can be a game-changer.
If you’re interested in trying this automation for your own workflow, feel free to download the script and psd file and test it in your projects!
🚀 Need help with automation? Reach out, and let’s optimize your workflow!