Skip to main content
Participant
January 11, 2024
Answered

saveAs() function causes disk error when called from javascript in Photoshop 25.3

  • January 11, 2024
  • 3 replies
  • 429 views

Although the following script worked previous, it appears to fail now with a disk error (-43).

Anyone else see this?  Any fixes or workarounds?

 

// Define the file path where you want to save the file
var filePath = "C:/Users/<myusername>/Desktop/file.jpg";

// Create a new File object with the file path
var jpgFile = new File(filePath);

// Define the JPEG save options
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;

// Save the active document with the defined file and JPEG save options
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);

 

This topic has been closed for replies.
Correct answer Chuck Uebele

Ok, I found your issue. you are defining your file path with the file name in it. Try this:

 

 

 

// Define the file path where you want to save the file
var filePath = new Folder("~/Desktop/");

// Create a new File object with the file path
var jpgFile = new File(filePath + '/jpgFile.jpg');

// Define the JPEG save options
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;

// Save the active document with the defined file and JPEG save options
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);

 

 

3 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
January 11, 2024

Ok, I found your issue. you are defining your file path with the file name in it. Try this:

 

 

 

// Define the file path where you want to save the file
var filePath = new Folder("~/Desktop/");

// Create a new File object with the file path
var jpgFile = new File(filePath + '/jpgFile.jpg');

// Define the JPEG save options
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;

// Save the active document with the defined file and JPEG save options
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);

 

 

Chuck Uebele
Community Expert
Community Expert
January 11, 2024

I would change the line declaring the file path to using the "~". This will make it so that that line works on Win and Mac, and any user that uses that computer.

var filePath = "/~/Desktop/file.jpg";

c.pfaffenbichler
Community Expert
Community Expert
January 11, 2024

I am a Mac-user myself, but as the Script seems otherwise fine I suspect there might be an issue with the Path. 

Did you replace »<myusername>« with your username? 

Does a File of that name and location already exist? 

Is enough space available? 

 

Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible?