Highlighted

Photoshop scripting question - Pasting from clipboard

Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

So i'm trying to automate some tasks which i'm unable to do from an action. 

 

I'm currently iterating through the open documents and wanting to copy & paste into another open document (will always be in pos 0)

 

So far i've got it copying correctly, i can paste it manually, but get an error when trying to do it by script.

The requested action requires that the target document is the frontmost document.

 

So far i have

for (var i = 1; i < app.documents.length; i++) {
    var doc = app.documents[i];
    app.activeDocument = doc;
    var imageWidth = doc.width;
    var imageHeight = doc.height;
    var imageAspectRatio = doc.width / doc.height;

    if( imageHeight > targetHeight ) {
        var tWidth = Math.round( imageAspectRatio * targetHeight );
        doc.resizeImage( tWidth, targetHeight );

        var fileName = getFileName( doc );
        
        doc.selection.selectAll();
        doc.selection.copy();
        
        app.documents[0].paste();
    }
}

What i want to do eventually is copy into a named folder group in the destination file

add before paste command: 

app.activeDocument = app.documents[0]
TOPICS
Actions and scripting, How to, Mac

Views

49

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

Photoshop scripting question - Pasting from clipboard

Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

So i'm trying to automate some tasks which i'm unable to do from an action. 

 

I'm currently iterating through the open documents and wanting to copy & paste into another open document (will always be in pos 0)

 

So far i've got it copying correctly, i can paste it manually, but get an error when trying to do it by script.

The requested action requires that the target document is the frontmost document.

 

So far i have

for (var i = 1; i < app.documents.length; i++) {
    var doc = app.documents[i];
    app.activeDocument = doc;
    var imageWidth = doc.width;
    var imageHeight = doc.height;
    var imageAspectRatio = doc.width / doc.height;

    if( imageHeight > targetHeight ) {
        var tWidth = Math.round( imageAspectRatio * targetHeight );
        doc.resizeImage( tWidth, targetHeight );

        var fileName = getFileName( doc );
        
        doc.selection.selectAll();
        doc.selection.copy();
        
        app.documents[0].paste();
    }
}

What i want to do eventually is copy into a named folder group in the destination file

add before paste command: 

app.activeDocument = app.documents[0]
TOPICS
Actions and scripting, How to, Mac

Views

50

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
Oct 05, 2020 0
Enthusiast ,
Oct 05, 2020

Copy link to clipboard

Copied

add before paste command: 

app.activeDocument = app.documents[0]

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
Reply
Loading...
Oct 05, 2020 1
Desbrina LATEST
Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

thank you, that worked

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
Reply
Loading...
Oct 05, 2020 0