Skip to main content
Participant
March 17, 2024
Question

Error 4 in Phtoshop jsx script

  • March 17, 2024
  • 1 reply
  • 265 views

Hi all,

 

I've tried to write a script to process 800 high resolution files that I have - I need to resize them to smaller dimensions, place another image on top of them and save with a new filename. With below script it fails with Error 4 on Line 2. Adobe Photoshop has full permission to folders on my device.

 

// Define the folder containing the files
var folderPath = "/Users/drcs/Desktop/Circuits/To print/Cropped_lowres/tracks/”;

// Define the path to the image to be placed on top
var overlayImagePath = "/Users/drcs/Desktop/Circuits/To print/Cropped_lowres/tracks/frame.png”;

// Open all files in the folder
var files = Folder(folderPath).getFiles(„*.png”); // Adjust the file extension if needed

// Open the overlay image
var overlayFile = new File(overlayImagePath);
var overlayDoc = app.open(overlayFile);

// Loop through each file
for (var i = 0; i < files.length; i++) {
    var file = files[i];
    
    // Open the file
    var doc = app.open(file);
    
    // Duplicate the overlay image
    var overlayLayer = overlayDoc.artLayers[0];
    overlayLayer.duplicate(doc, ElementPlacement.PLACEATBEGINNING);
    
    // Close the overlay document without saving changes
    overlayDoc.close(SaveOptions.DONOTSAVECHANGES);
        
    // Resize the image
    doc.resizeImage(2480, 3543);
    
    // Save the modified image under a new filename
    var fileName = file.name.slice(0, -4); // Remove the file extension (.png)
    var newFileName = fileName + „_framed.png”; // Append "_resized" to the original filename
    var newFile = new File(folderPath + newFileName); // Construct the new file path
    
    doc.saveAs(newFile);
    
    // Close the document
    doc.close();
}

 

Any chance that you can help with this one guys?

This topic has been closed for replies.

1 reply

Legend
March 17, 2024

var folderPath = "/Users/drcs/Desktop/Circuits/To print/Cropped_lowres/tracks/;

 

Incorrect quotes at the end of the line. Do not use complex editors to edit scripts. Use plain text without styles or special characters.

 

Participant
March 18, 2024

wow, good eye, thank you!