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

photoshop scripting

Community Beginner ,
May 10, 2022 May 10, 2022

I want to be a save png file with a script, in script same file name same folder

Thanks in advance

TOPICS
Actions and scripting
1.5K
Translate
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
Adobe
Community Expert ,
May 10, 2022 May 10, 2022

There are many examples in the forum. Do you know how to modify/hack an existing script?

 

Do you want to use Save As or Export > Save for Web (Legacy)?

 

What settings?

 

If the current file was say a JPEG or PSD etc, do you want the current file to remain open by saving a copy, or should the current file now be the PNG?

 

Do you wish to silently overwrite any existing PNG file with the same name, skip or prompt?

Translate
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 Beginner ,
May 10, 2022 May 10, 2022

I want to use save as and current file is jpg and i want to save png file and close jpeg and jpg remain same in folder and png file will be there as same name and save in same folder which jpg file contains and i dont know how to use javascript 

Thanks

 

 

 

Translate
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
LEGEND ,
May 11, 2022 May 11, 2022

So you don't need file name and a location to be adequate to script properties. Now you say of other prerequisites. Save below script as 'JPG to PNG.jsx' to 'Presets / Scripts' folder of your Ps. Launch app and when your .jpg is open, choose 'JPG to PNG' from 'File / Scripts' menu:

 

with(activeDocument) saveAs(fullName, new PNGSaveOptions), close()

 

Translate
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
LEGEND ,
May 10, 2022 May 10, 2022
activeDocument.saveAs(File($.fileName), new PNGSaveOptions)
Translate
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 ,
May 11, 2022 May 11, 2022

This script uses Save As a Copy:

 

/*
Save As PNG to Parent Folder
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-scripting/td-p/12934278
11th May 2022, v1.0 - Stephen Marsh
*/

#target photoshop

if (app.documents.length !== 0) {

    // Remove the filename extension
    var docName = activeDocument.name.replace(/\.[^\.]+$/, '');

    try {
        // Use the previously saved directory path
        var docPath = activeDocument.path;
    } catch (e) {
        // If unsaved, prompt for the save path
        var docPath = Folder.selectDialog('Unsaved file, select the save directory:');
    }

    // File Path & Naming
    var savePNG = new File(docPath + '/' + docName + '.png');

    // Conditional overwrite check
    if (savePNG.exists) {
        // true = 'No' as default active button
        if (!confirm('File exists, overwrite: Yes or No?', true))
            // throw alert('Script cancelled!');
            throw null;
    }

    var saveOptions = new PNGSaveOptions();
    saveOptions.compression = 0; // 0-9
    saveOptions.interlaced = false;
    activeDocument.saveAs(savePNG, saveOptions, true, Extension.LOWERCASE);
    activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    // alert('PNG saved to: ' + '\r' + docPath.fsName);
    // docPath.execute();

} else {
    alert('You must have a document open!');
}

 

Instructions for saving/installing/running:

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save the text file as .txt
  5. Rename the file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

 

Translate
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 ,
May 11, 2022 May 11, 2022

This version uses Export - Save for Web:

 

/*
Export Save for Web PNG to Parent Folder
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-scripting/td-p/12934278
11th May 2022, v1.0 - Stephen Marsh
*/

#target photoshop

if (app.documents.length !== 0) {

    // Remove the filename extension
    var docName = activeDocument.name.replace(/\.[^\.]+$/, '');

    try {
        // Use the previously saved directory path
        var docPath = activeDocument.path;
    } catch (e) {
        // If unsaved, prompt for the save path
        var docPath = Folder.selectDialog('Unsaved file, select the save directory:');
    }

    // File Path & Naming
    var saveForWebPNG = new File(docPath + '/' + docName + '.png');

    // Conditional overwrite check
    if (saveForWebPNG.exists) {
        // true = 'No' as default active button
        if (!confirm('File exists, overwrite: Yes or No?', true))
            // throw alert('Script cancelled!');
            throw null;
    }

    var pngOptions = new ExportOptionsSaveForWeb();
    pngOptions.PNG8 = false;
    pngOptions.transparency = true;
    pngOptions.interlaced = false;
    pngOptions.quality = 100;
    pngOptions.includeProfile = true;
    pngOptions.format = SaveDocumentType.PNG;
    activeDocument.exportDocument(saveForWebPNG, ExportType.SAVEFORWEB, pngOptions);
    activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    // alert('PNG saved to: ' + '\r' + docPath.fsName);
    // docPath.execute();

} else {
    alert('You must have a document open!');
}
Translate
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 Beginner ,
May 13, 2022 May 13, 2022

thanku very much its work

Translate
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
LEGEND ,
May 13, 2022 May 13, 2022

What about mine? Most likely too short to notice loll

Translate
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 Beginner ,
May 13, 2022 May 13, 2022

Thanks for help i really appreciate to you, you make time for me

Translate
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
LEGEND ,
May 13, 2022 May 13, 2022
LATEST

Thank You. If you find for us a little time mark some replies as correct 😉

Translate
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