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

Photoshop scripting documentation

New Here ,
May 05, 2023 May 05, 2023

Copy link to clipboard

Copied

Hello devs,

 

I am planning to write some scripts for photoshop for a friend of mine. As of my knowlege the latest documentation for scripting dates back to 2020. Is there an active guide anywhere? I am looking to manipulate layers. I would like to distribute two uneven layers horizontally and center them vertically to be persice.

 

Any help is much appreciated. 

TOPICS
Actions and scripting

Views

1.7K

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

New Here , May 13, 2023 May 13, 2023

Hello @Stephen_A_Marsh , thank you for your reply.

Scripting Listener dowsnt work on Apple MacBookPro 13-inch, M2, 2022.
I was able to write the script with help from the documentation above. 

 

var doc = app.activeDocument;

var selectedLayers = getSelectedLayers();

if (selectedLayers.length == 2) {
    
    var result = idLayers(selectedLayers);

    var object = result.object
    var scale = result.scale

    var layersToDistribute = [object, scale];
    h0Vcenter(object)
    h0Vcenter(scale)
  
...

Votes

Translate

Translate
Adobe
Community Expert ,
May 06, 2023 May 06, 2023

Copy link to clipboard

Copied

I am aware of no newer version available as pdf. 

 

If you are new to Photoshop Scripting, I wonder if you might not be better off going with UXP right away instead of ESTK. 

 

Please post screenshots to illustrate the exact and complete layer structure of the image/s in question and th eintended operation. 

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 ,
May 06, 2023 May 06, 2023

Copy link to clipboard

Copied

There are many features which aren't covered in the Scripting DOM, which is where AM or Action Manager code and the ScriptingListener plugin comes in handy.

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
New Here ,
May 13, 2023 May 13, 2023

Copy link to clipboard

Copied

Hello @Stephen_A_Marsh , thank you for your reply.

Scripting Listener dowsnt work on Apple MacBookPro 13-inch, M2, 2022.
I was able to write the script with help from the documentation above. 

 

var doc = app.activeDocument;

var selectedLayers = getSelectedLayers();

if (selectedLayers.length == 2) {
    
    var result = idLayers(selectedLayers);

    var object = result.object
    var scale = result.scale

    var layersToDistribute = [object, scale];
    h0Vcenter(object)
    h0Vcenter(scale)
    distributeRow(object, scale);
} else {
    alert("Please select 2 players");
}
function h0Vcenter(layer) {
    var currentX = layer.bounds[0].value;
    var currentY = layer.bounds[1].value;
    var deltaX = -currentX;

    var centerY = doc.height.value / 2;
    var layerHeight = layer.bounds[3].value - layer.bounds[1].value;
    var targetY = centerY - layerHeight / 2;
    var deltaY = targetY - currentY;

    layer.translate(deltaX, deltaY);
}
function idLayers(layers) {
    var objectLayer = layers[0];
    var scaleLayer = layers[1];
    var objectWidth = objectLayer.bounds[2].value - objectLayer.bounds[0].value;
    var objectHeight = objectLayer.bounds[3].value - objectLayer.bounds[1].value;
    var scaleWidth = scaleLayer.bounds[2].value - scaleLayer.bounds[0].value;
    var scaleHeight = scaleLayer.bounds[3].value - scaleLayer.bounds[1].value;

    if (objectWidth * objectHeight < scaleWidth * scaleHeight) {
        var tempLayer = objectLayer;
        objectLayer = scaleLayer;
        scaleLayer = tempLayer;
    }

    return { object: objectLayer, scale: scaleLayer };
}
function getSelectedLayers() {
    var ActLay = app.activeDocument.activeLayer;
    ActLay.allLocked = true;
    var L = app.activeDocument.layers.length;
    var selLayers = new Array();
    for(var i = 0; i < L; i++) {
        var LayerType = app.activeDocument.layers[i].typename;
        var layerRef = app.activeDocument.layers[i];
        if (LayerType == "LayerSet" ) {
            var refLength = layerRef.layers.length;
            for(var j = 0; j < refLength; j++) {
                var refLay = layerRef.layers[j];
                if (refLay.allLocked == true){selLayers.push(refLay)}
            }
            continue;
        }
        if (layerRef.allLocked == true) {selLayers.push(layerRef)}
    }
    ActLay.allLocked = false;
    return selLayers;
}
function distributeRow(layer2, layer1) {
   
    var layer1Left = layer1.bounds[0].value;
    var layer1Right = layer1.bounds[2].value;
    var layer2Left = layer2.bounds[0].value;
    var layer2Right = layer2.bounds[2].value;

    var totalWidth = (layer1Right - layer1Left) + (layer2Right - layer2Left);
    var remainingWidth = doc.width.value - totalWidth;
    var spaceBetween = Math.round(remainingWidth / 3);

    var layer1Delta = spaceBetween - layer1Left;
    var layer2Delta = (spaceBetween * 2) + (layer1Right - layer1Left) - layer2Left;

    layer1.translate(layer1Delta, 0);
    layer2.translate(layer2Delta, 0);   
}

 so is UXP the new way of writing scripts or what?

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 ,
May 14, 2023 May 14, 2023

Copy link to clipboard

Copied

quote

Scripting Listener dowsnt work on Apple MacBookPro 13-inch, M2, 2022.

Did you disable »Allow Tool Recording« in the Actions Panel? 

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 ,
May 14, 2023 May 14, 2023

Copy link to clipboard

Copied

You may have to »Open using Rosetta« for ScriptingListener.plugin to record. 

Screenshot 2023-05-14 at 11.43.35.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
Community Expert ,
May 14, 2023 May 14, 2023

Copy link to clipboard

Copied

quote

 so is UXP the new way of writing scripts or what?


By @y.antypas

 

UXP is certainly the future that is currently mapped.

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 ,
May 14, 2023 May 14, 2023

Copy link to clipboard

Copied

I am curious how many maps we’re going to see yet … 

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 ,
May 14, 2023 May 14, 2023

Copy link to clipboard

Copied

Yeah, I'm not bothering with UXP yet, there have been too many previous forks in the road.

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 ,
May 14, 2023 May 14, 2023

Copy link to clipboard

Copied

LATEST

I tried and so far I have not gotten far … coming from ESTK Scripting it seems a considerable change. 

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