• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Edit script to save psd instead of png

Explorer ,
Nov 09, 2018 Nov 09, 2018

Copy link to clipboard

Copied

I use this script quite often. It was enhanced yesterday by awesome people on here. I was wondering if it's possible, instead of it saving as a png to save as a psd file, but with the image size measurements still included? Many, many thanks in advance

var pth = "~/Desktop"; // path to save the file, the default save to the desktop, change as needed 

 

var tmp = app.preferences.rulerUnits; 

 

app.preferences.rulerUnits = Units.MM; 

 

var w = Math.round(activeDocument.width.value); 

var h = Math.round(activeDocument.height.value); 

 

var file = new File(pth+ "/" + w+"x"+h + ".png"); 

 

save_as_png(file); 

 

app.preferences.rulerUnits - tmp; 

 

 

 

function save_as_png(file, filter, none, comp) 

    { 

    try { 

        if (filter == undefined) filter = "PNGFilterAdaptive"; 

        if (none == undefined) none = true; 

        if (comp == undefined) comp = 9; 

 

        var d = new ActionDescriptor(); 

        var d1 = new ActionDescriptor(); 

        if (none) 

            d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceNone")); 

        else 

            d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceAdam7")); 

 

        d1.putEnumerated(stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilter"), stringIDToTypeID(filter)); 

        d1.putInteger(stringIDToTypeID("compression"), comp); 

        d.putObject(stringIDToTypeID("as"), stringIDToTypeID("PNGFormat"), d1); 

        d.putPath(stringIDToTypeID("in"), file); 

        d.putBoolean(stringIDToTypeID("copy"), true); 

        executeAction(stringIDToTypeID("save"), d, DialogModes.NO); 

        } 

    catch (e) { alert(e); throw(e); } 

    } 

TOPICS
Actions and scripting

Views

3.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 09, 2018 Nov 09, 2018

This is what I came up with:

//https://forums.adobe.com/thread/2558835

var pth = "~/Desktop"; // path to save the file, the default save to the desktop, change as needed

var tmp = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.MM;

var w = Math.round(activeDocument.width.value);

var h = Math.round(activeDocument.height.value);

var saveFile = new File(pth + "/" + w + "x" + h + ".psd");

SavePSD(saveFile);

app.preferences.rulerUnits = tmp;

function SavePSD(saveFile){  

psdSaveOptions = new Pho

...

Votes

Translate

Translate
Adobe
People's Champ ,
Nov 09, 2018 Nov 09, 2018

Copy link to clipboard

Copied

Please, finally read the documentation.

Untitled-1.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 09, 2018 Nov 09, 2018

Copy link to clipboard

Copied

Thanks so much for your time, I know you've been so patient and helpful to me. I really appreciate it.

I have tried changing the png to psd myself but I get a NaN result.

var pth = "~/Desktop";

var tmp = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.MM;

var w = Math.round(activeDocument.width.value);

var h = Math.round(activeDocument.height.value);

var file = new File(pth+ "/" + w+"x"+h + ".psd");

app.preferences.rulerUnits - tmp;

function SavePSD(saveFile){  

psdSaveOptions = new PhotoshopSaveOptions();  

psdSaveOptions.embedColorProfile = true;  

psdSaveOptions.alphaChannels = true;

psdSaveOptions.layers = true;   

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

}; 

I can't figure out what I've done wrong 😕

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 09, 2018 Nov 09, 2018

Copy link to clipboard

Copied

What does NaN mean? )

You forgot to insert a line to call a function.

SavePSD(file)

And it works.

And there is a typo (it looks like mine)

app.preferences.rulerUnits - tmp;

must be

app.preferences.rulerUnits = tmp;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2018 Nov 09, 2018

Copy link to clipboard

Copied

This is what I came up with:

//https://forums.adobe.com/thread/2558835

var pth = "~/Desktop"; // path to save the file, the default save to the desktop, change as needed

var tmp = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.MM;

var w = Math.round(activeDocument.width.value);

var h = Math.round(activeDocument.height.value);

var saveFile = new File(pth + "/" + w + "x" + h + ".psd");

SavePSD(saveFile);

app.preferences.rulerUnits = tmp;

function SavePSD(saveFile){  

psdSaveOptions = new PhotoshopSaveOptions();  

psdSaveOptions.embedColorProfile = true;

psdSaveOptions.alphaChannels = true;  

psdSaveOptions.layers = true;

psdSaveOptions.annotations = true;

psdSaveOptions.spotColors = true;

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

}

P.S. I believe that the NaN result (not a number) in the JavaScript Console of ESTK was due to the erroneous - hyphen rather than equal = sign. Once I fixed that the original ruler units were returned (line 09).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 12, 2018 Nov 12, 2018

Copy link to clipboard

Copied

LATEST

Ah thank you so much! I really appreciate your hard work!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines