Skip to main content
Participant
June 4, 2014
Answered

Help! Fix my javascript to save a bmp with suffix in the same folder as the previous save.

  • June 4, 2014
  • 2 replies
  • 1332 views

Here's my current javascript:

#target photoshop

// sets document preferences to inches

app.preferences.rulerUnits = Units.INCHES

// these are our values for the END RESULT width and height (in inches) of our image

var fWidth = 11.73;

var fHeight = 5.97;

var CurrentDLPFile=app.activeDocument

var CurrentDLPFileName= CurrentDLPFile.name

var CurrentDLPFilePath="~/Desktop/fetch"

var f = File.saveDialog('Save Where?',''); 

// in case we double clicked the file

app.bringToFront();

// resizes the canvas to 11.73 x 5.97 inches

CurrentDLPFile.resizeCanvas(UnitValue(fWidth,"in"),UnitValue(fHeight,"in"));

// flattens all layers

CurrentDLPFile.flatten();

// saves as photoshop file

if (f!=null) CurrentDLPFile.saveAs(f,undefined);

// splits channels

CurrentDLPFile.splitChannels();

// converts active K seperation to bitmap form

var bitsaveoptions = new BitmapConversionOptions()

bitsaveoptions.method = BitmapConversionType.HALFTONESCREEN

bitsaveoptions.angle = 45

bitsaveoptions.frequency = 55

bitsaveoptions.resolution = 300

bitsaveoptions.shape = BitmapHalfToneType.ROUND

app.activeDocument.changeMode(ChangeMode.BITMAP,bitsaveoptions);

// THIS IS WHERE I'M HAVING ISSUES- I want to save the file (which at this point is a bmp), with a suffix of 1 in the same folder; and then close the file.

var doc = app.activeDocument;

var docName = doc.name;

docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/):docName = [docName, docName];

var suffix = '_1';

var saveName = new File(decodeURI(doc.path)+'/'+docName[1]+suffix+'.bmp');

function saveFile(app.activeDocument, saveName);

This topic has been closed for replies.
Correct answer C_Barnes

I figured it out, here's for anyone else who is struggling with a similar problem:

var CurrentDLPFile=app.activeDocument

// saves active doc as photoshop file

if (f!=null) CurrentDLPFile.saveAs(f,undefined);

//renames active document to whatever was saved

var CurrentDLPFile = app.activeDocument.name

//assigns the location of the saved psd

var psdPath = activeDocument.path

saveBMP = new BMPSaveOptions();

saveBMP.alphaChannels = false;

saveBMP.depth = BMPDepthType.ONE;

saveBMP.flipRowOrder = false;

saveBMP.rleCompression = false;

saveBMP.osType = OperatingSystem.WINDOWS;

var doc = app.activeDocument; 

var Name = doc.name.replace(/\.[^\.]+$/, '');  

var Suffix = "1"; 

var saveFile = File(psdPath + "/" + Name + Suffix + ".bmp");

activeDocument.saveAs(saveFile, saveBMP, true, Extension.LOWERCASE); 

activeDocument.close( SaveOptions.DONOTSAVECHANGES );

2 replies

C_BarnesAuthorCorrect answer
Participant
June 5, 2014

I figured it out, here's for anyone else who is struggling with a similar problem:

var CurrentDLPFile=app.activeDocument

// saves active doc as photoshop file

if (f!=null) CurrentDLPFile.saveAs(f,undefined);

//renames active document to whatever was saved

var CurrentDLPFile = app.activeDocument.name

//assigns the location of the saved psd

var psdPath = activeDocument.path

saveBMP = new BMPSaveOptions();

saveBMP.alphaChannels = false;

saveBMP.depth = BMPDepthType.ONE;

saveBMP.flipRowOrder = false;

saveBMP.rleCompression = false;

saveBMP.osType = OperatingSystem.WINDOWS;

var doc = app.activeDocument; 

var Name = doc.name.replace(/\.[^\.]+$/, '');  

var Suffix = "1"; 

var saveFile = File(psdPath + "/" + Name + Suffix + ".bmp");

activeDocument.saveAs(saveFile, saveBMP, true, Extension.LOWERCASE); 

activeDocument.close( SaveOptions.DONOTSAVECHANGES );

pixxxelschubser
Community Expert
Community Expert
June 4, 2014

Hi c_barnes,

Try this to get the saveName with path for your saveFile:

var doc = app.activeDocument;

var saveFile = File(File(doc.path)+"/"+doc.name.replace (/\.bmp$/,'_1.bmp'));

alert(saveFile);

Is this ok for you?

C_BarnesAuthor
Participant
June 5, 2014

Hi pixxel,

ExtendScript still won't run my code:

// saves K seperation to bitmap form

saveBMP = new BMPSaveOptions();

saveBMP.alphaChannels = false;

saveBMP.depth = BMPDepthType.ONE;

saveBMP.flipRowOrder = false;

saveBMP.rleCompression = false;

saveBMP.osType = OperatingSystem.WINDOWS;

var doc = activeDocument;

var saveFile = File(File(doc.path)+"/"+doc.name.replace (/\.bmp$/,'_1.bmp'));

activeDocument.saveAs(saveFile, saveBMP, true, Extension.LOWERCASE); 

activeDocument.close( SaveOptions.DONOTSAVECHANGES );

activeDocument.close()

^the bolded line above is where it runs into issues... any ideas? Thanks for your help!