Skip to main content
Participating Frequently
July 11, 2022
Question

Script photoshop/illustrator

  • July 11, 2022
  • 2 replies
  • 751 views

Hello,

I would like to make a Photoshop script to open a folder with images that I want to open with a dynamic vector layer (which directs to Illustrator).
Is this possible?

Thank you.

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
July 11, 2022

@Thomas25199145gknj wrote:

 

I would like to make a Photoshop script to...



Does this mean that you have some knowledge/ability to script and just need some pointers to get you started or to overcome points where you have stalled?

 

Or does this mean that you can't script and want someone to write the script for you?

 

The replies would be different in each case.

Participating Frequently
July 11, 2022

We don't have ability to write a script by ourselves, we only have notions in js, but it is not enough to solve the problem 😕😕
Thanks 


c.pfaffenbichler
Community Expert
Community Expert
July 11, 2022

This would offer a dialog for file selection, open the selected files, duplicate the lowest layer, convert it to a smart object, save the image as a psd and open the smart object. 

// 2022, use it at your own risk;
var theSourceFiles = selectFile (true);
if (theSourceFiles != null) {
    for (var m = 0; m < theSourceFiles.length; m++) {
        var thisFile = app.open(File(theSourceFiles[m]));
        var theDup = thisFile.layers[thisFile.layers.length - 1].duplicate();
        thisFile.activeLayer = theDup;
        theDup.name = thisFile.name;
        convertToSmartObject();
        saveAsPsd (thisFile, thisFile.path, thisFile.name.match(/(.*)\.[^\.]+$/)[1], false);
        openSmartObject();
    };
};
////// select file //////
function selectFile (multi) {
    if (multi == true) {var theString = "please select files"}
    else {var theString = "please select one file"};
    if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.png', multi)}
    else {var theFiles = File.openDialog (theString, getFiles, multi)};
    ////// filter files  for mac //////
    function getFiles (theFile) {
        if (theFile.name.match(/\.(jpg|tif|psd|png)$/i) || theFile.constructor.name == "Folder") {
            return true
            };
        };
    return theFiles
    };
////// open smart object //////
function openSmartObject () {
    var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
    var desc2 = new ActionDescriptor();
    executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );
    return activeDocument;
    };
////// convert to smart object //////
function convertToSmartObject () {
var desc108 = new ActionDescriptor();
var ref77 = new ActionReference();
ref77.putEnumerated( charIDToTypeID( "Mn  " ), charIDToTypeID( "MnIt" ), stringIDToTypeID( "newPlacedLayer" ) );
desc108.putReference( charIDToTypeID( "null" ), ref77 );
executeAction( charIDToTypeID( "slct" ), desc108, DialogModes.NO );
};
////// save psd //////
function saveAsPsd (thedoc, docPath, basename, overwrite) {
// check for existing file
    if (overwrite == false && File(docPath+'/'+basename+'.psd').exists == true) {
        var theConfirm = confirm("overwrite existing file");
        if (theConfirm == false) {return false}
        };
// make copy and save
    if (app.documents.length > 0) {
    try {
    saveOpts = new PhotoshopSaveOptions();
    saveOpts.embedColorProfile = true;
    saveOpts.alphaChannels = true;
    saveOpts.layers = true;
    saveOpts.spotColors = true;
    thedoc.saveAs((new File(docPath+'/'+basename+'.psd')),saveOpts,false);
    }
    catch (e) {docName+" failed"}
    }
    };

 

c.pfaffenbichler
Community Expert
Community Expert
July 11, 2022

Do you mean a Vector Smart Object? 

Opening the SO via Script should not be a problem, but do you want the Script to perform operations in Illustrator after that? 

Participating Frequently
July 11, 2022

No I don't want the script to perform any action on Illustrator but only to open to Illustrator

Thanks

c.pfaffenbichler
Community Expert
Community Expert
July 11, 2022

Then 

openSmartObject();
////// open smart object //////
function openSmartObject () {
    var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
    var desc2 = new ActionDescriptor();
    executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );
    return activeDocument;
    };

schould suffice (provided the SO is the active Layer).