Script to create new .psd with embedded raw file as smart object

New Here ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

I have a collection of camera raw files.  I would like to create a script that would embed each raw file as a smart object in a new .psd file with the same name as the original raw file.  I'd like to do this from Bridge.  I've done other photoshop scripting but don't see how to do this. 

TOPICS
Actions and scripting

Views

356

Likes

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
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

But the Image Processor script also uses the API open(), and it is not opening the RAW files as smart objects when Open as Smart Object is checked as you are suggesting—unless something has changed with PS22. 

Likes

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
Most Valuable Participant ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

I do not know if it changed in PS 2021 I know it works in PS2021 the Windows 10 screen capture I posted showed that it works in PS2021 that way.  I'll test an older version now. I'll test CS6 for it will also use an older ACR.

 

JJMack

Likes

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
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

I don’t think it is working for @groucho90 either. I’m on OSX Mojave, PS21, Camera RAW 12.4. In any case the advantage of the simpler open as smart object function is you don’t have to check or set the Camera RAW preferences or interact with a script dialog. 

Likes

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
New Here ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

If you are referring to the "low performance" version of your script, yes, it is working fine for me.  If you are referring to something else "not working" I'm confused..   [I see the "smart object thunbnail" tool tip when I hover over the thumbnail in layers in the resulting .psd file.]  OSX 10.14, PS 22.1.1, latest ACR.  It is actually fine that the script finds all the raw files in a given folder, that is what I would do anyway.  If I was selecting in Bridge I'd just skip files with other types.  As I said before this is something I plan on using only once on a collection of raw files, immediately after unloading a camera.  If I find the need to rerun the process on one or more raw files I will revisit the script or the overall approach.  Thanks again!

Likes

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
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

If you are referring to something else "not working" I'm confused..

 

It’s the Image Processor.jsx script @JJMack was suggesting that isn’t working for me—the saved PSDs are never smart objects. 

Likes

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
Most Valuable Participant ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

There seems to be differences between PS on PC and Mac 

JJMack

Likes

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
Most Valuable Participant ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

It may have the screen Capture I post showed it worke in PS2021. I Just tested CS6 it Open and ACR 9.1 created a backgrounf layer.

Capture.jpg

JJMack

Likes

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
Most Valuable Participant ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

It did change at some point time I just tested Bridge, CS6, and ACR 9.1.1.   Image Processor and ACR 9.1.1 Created Background layers not smart Object Layers.  Testing Bridge CC, Photoshop CC2014 and  ACR 13.1.  Image Processor and ACR 13.1 create Smart Object layers  not background layers.

JJMack

Likes

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
Most Valuable Participant ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

I use windows there seems to be more problem lately with PS on Mac than PS on Windows

JJMack

Likes

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
New Here ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Hi Rob,  In this second version of the script, with the openAsSmart() function, where would you override and set the bit depth and color profile?  You say it could be over ridden in the open function.  I think this is being done with the executeAction function?  Could you add the code to do those two things?  This is beyond me right now but I would like to learn.  (And is there someplace online I could find more "real world" programming examples like this?)

Likes

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
Adobe Community Professional ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

Here I’m setting the profile, bit depth and resolution in the open function—I’ve annotated the lines:

 

Also, not sure how you are using this, but I have an InDesign script that will place RAW files as smart objects via the BridgeTalk API.

 

 

#target photoshop

var f = Folder.selectDialog("Select the folder containing .CR2 Raw files"); 
if(f != null){ 
    fa = f.getFiles(/\.(CR2)$/i);
}


for (var i = 0; i < fa.length; i++){
    openAsSmart(fa[i])
    var d = app.activeDocument
    var n = d.name;
    //save in the same folder as a .PSD file
    var so = new PhotoshopSaveOptions({embedColorProfile:true, layers:true});
    var sPath = f + "/" + n + ".psd"
    d.saveAs(new File(sPath), so);
    d.close();

};   



/**
* Use ActionDescriptors to open RAW as a smart object
* @Param the file path 
* @Return void 
* 
*/
function openAsSmart(p){
    var d1 = new ActionDescriptor();
    d1.putPath( stringIDToTypeID( "null" ), new File( p ) );
    var d2 = new ActionDescriptor();
    //profile
    //ProPhoto
    //d2.putEnumerated( stringIDToTypeID( "colorSpace" ), stringIDToTypeID( "colorSpace" ), charIDToTypeID( "ProP" ) );
    //adobeRGB
    d2.putEnumerated( stringIDToTypeID( "colorSpace" ), stringIDToTypeID( "colorSpace" ), stringIDToTypeID( "adobeRGB1998" ) );
    
    //bit depth "BD08" for 8-bit and "BD16" for 16 bit
    d2.putEnumerated( stringIDToTypeID( "bitDepth" ), stringIDToTypeID( "bitDepth" ), charIDToTypeID( "BD08" ) );
    
    //Resolution
    d2.putDouble( stringIDToTypeID( "resolution" ), 350.000000 );
    
    d1.putObject( stringIDToTypeID( "as" ), stringIDToTypeID( "Adobe Camera Raw" ), d2 );
    d1.putBoolean( stringIDToTypeID( "smartObject" ), true );
    executeAction( stringIDToTypeID( "open" ), d1, DialogModes.NO );
}

 

 

Likes

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
New Here ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Hi Rob,

 

Thanks, this looks good and I will study it.  I don't know anything about the ActionDescriptor object.   I'll create a second script and compare output of this one to the original that I am using and works fine.  The performance issues of the first script are OK with me since I only intend to run it once on a collection of raw files.

 

Could you point me at a good programming reference for the Photoshop API?  Not a reference manual for the API, which I have, but a programming guide?  Something with a lot of examples?  Or could you point me at someplace online where I could find a good collection of PS scripts in Javascript?

 

Also I didn't know that Bridge can be programmed.  Assume that is what the BridgeTalk API is.  I would be interested in seeing your InDesign script.

 

Thanks again,  Lee

Likes

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
Adobe Community Professional ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Likes

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
Adobe Community Professional ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

Also, here is the Photoshop guide page along with sample links:

https://www.adobe.com/devnet/photoshop/scripting.html

the samples:

http://download.adobe.com/pub/adobe/photoshop/mac/13.x/Samples_E.zip

 

A searchable Photoshop API:

https://www.indesignjs.de/extendscriptAPI/photoshop-latest/#about.html

InDesign API:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

 

BridgeTalk isn’t related to the Bridge application. It’s a class that can be used to communicate between Adobe applications via Javascript—unfortuunately its syntax is challenging. Here‘s a guide:

https://extendscript.docsforadobe.dev/interapplication-communication/communicating-through-messages....

 

Here’s the InDesign script—It asks for a RAW file to place, converts it into a PSD smart object, saves it to a folder in the same directory as the RAW file and places the PSD:

 

https://shared-assets.adobe.com/link/de1366b2-faab-42ee-5c76-3cbb75481357

 

Likes

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
Adobe Community Professional ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

LATEST

This is the annotated Bridgetalk template I use for creating InDesign to Photoshop scripts:

 

 

 

//InDesign as the script application
//#target indesign
#targetengine "session" 

var arr = [true, "Hello", 50];
var obj = {h:350, w:500}

//Run a BridgeTalk Photoshop function
runPhotoshop("Hello", arr, 99.99, obj);


/**
* Run function in ID after BT function is completed 
*  the string or object returned from Photoshop 
*  void 
* 
*/
function runID(s){
    //if the return is an array as a string use split
    //alert("Running New ID Fuction—string returned from Photoshop: "  + s.split(",")[1])
    alert("Running New ID Fuction—string returned from Photoshop: "  + s)
}


/**
* Opens Photoshop via Bridgetalk and runs psScript 
*  the string variable sent into the Photoshop fuction
*  a an array variable 
*  n a number variable 
*  o an object variable 
*  value void 
* 
*/
function runPhotoshop(s, a, n, o){
    
    //open Photoshop and run psScript
    var bt = new BridgeTalk();  
    bt.target = "photoshop";  
    //a string representaion of variables and the function to run. 
    //a string var. Note string single, double quote syntax '"+s+"'
    bt.body = "var s = '"+s+"';" 
    //an array. Note use toSource()
    bt.body += "var a = "+a.toSource()+";" 
    //a number
    bt.body += "var n = "+n+";"
    //an object. Note use toSource()
    bt.body += "var o = "+o.toSource()+";" 
    //the function and the call
    bt.body += psScript.toString() + "psScript();";

    bt.onResult = function(resObj) { 
        runID(resObj.body)
    }  
    bt.onError = function( inBT ) { alert(inBT.body); };  
    bt.send(8);  
      
    function psScript() {  
        alert("Photoshop Running")
        //make a new string to return
        var ns = s + " World " + a[2] + "  " + n + "  " + o.h;
        //returns the array as a string
        //return a
        return ns
    }  
}

 

 

Likes

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