Skip to main content
Inspiring
February 19, 2024
Question

Script that opens a selected InDesign image in Photoshop

  • February 19, 2024
  • 3 replies
  • 1396 views

I used to have an old script that would open any image from InDesign in Photoshop in one click.

However somehow, with the newer version of InDesign, none of the scripts that I had or found online, work. (I am on Mac, InDesign 2023 and Photoshop 2024).

I am not a scripter, so I've asked ChatGPT to write one. After about an hour of several unsuccesful attempts we have finally managed to produce a working Java Script! So here I share it with you. You are welcome to improve it.

imagesToPS();

function imagesToPS() {
    if (app.selection.length > 0) {
        var selectedPageItem = app.selection[0]; // Assuming the first selected item is a page item
        if (selectedPageItem.constructor.name == "Image") {
            var filePath = selectedPageItem.itemLink.filePath;
            openImageInPhotoshop(filePath);
        } else {
            alert("Selected item is not an image.");
        }
    } else {
        alert("No items selected.");
    }
}

function openImageInPhotoshop(filePath) {
    try {
        var bt = new BridgeTalk();
        bt.target = "photoshop";
        bt.body = 'app.bringToFront(); app.open(new File("' + filePath + '"));';
        bt.onError = function (inBT) {
            alert("Error opening image in Photoshop: " + inBT.body);
        };
        bt.onResult = function (resObj) {};
        bt.send();
    } catch (e) {
        alert("Error opening image in Photoshop: " + e);
    }
}

 

3 replies

Peter Spier
Community Expert
Community Expert
March 5, 2025

I'm very late to this year-old thread, but I'm a little surprised nobody mentioned putting your original script in a "Version X.0 Scripts" subfolder in the scripts panel folder (case sensitive, and without the quotes, and subtitute the last version number where the script worked for X.0).

rob day
Community Expert
Community Expert
February 20, 2024

Hi @Sesamme , i assume you want to run a Photshop script on the opened file otherwise you would just use alt/option-double-click as @Rene Andritsch suggests? I use this template which exposes a Photoshop JS that is easier to edit than the ChatGPT version’s body string

 

imagesToPS()


/**
* Open all of the doument’s linked images 
* and runs the Photoshop function psScript()
* return void
*/

function imagesToPS(){
    var bt = new BridgeTalk();  
    bt.target = "photoshop"; 
    if (app.documents.length > 0) {
        var lnks = app.documents[0].links;
        for (var i = 0; i < lnks.length; i++){
            if (lnks[i].parent.constructor.name == "Image") {
                openImage(lnks[i].filePath, bt);
            } 
        };   
    } else {
        alert("No Documents Open")
        return
    }
}

/**
* Open Image in Photoshop 
* @ param Image’s file path 
* @ param Bridgetalk instance 
* return void
*/
function openImage(pa, bt){
    bt.body = psScript.toString() + "\rpsScript('"+pa+"');";
    bt.onError = function( inBT ) { alert(inBT.body); };  
    bt.onResult = function(resObj) { } 
    bt.send(1000);   

    //the photoshop script to run on the opened file
    function psScript(pa) {  
        var f = open (File(pa));
        //do something
        f.close()
    }  
};
SesammeAuthor
Inspiring
February 21, 2024

I do not need to perform any actitons - just open in Photoshop. But ALT click doesn't work for me unless I am clicking something wrong. 

Strangely your script crashes InDesign! 🙂

However I do have a similar sript, but it opens all images, not just one selected. I actually gave it to ChatGPT and asked to rework it so that it opens one image - that's how I got my script, which works...

This is the script I gave to ChatGPT:

 

imagesToPS();

function imagesToPS() {
    var bt = new BridgeTalk();
    bt.target = "photoshop";

    if (app.documents.length > 0) {
        var lnks = app.documents[0].links;
        for (var i = 0; i < lnks.length; i++) {
            if (lnks[i].parent.constructor.name == "Image") {
                openImage(lnks[i].filePath, bt);
            }
        }
    } else {
        alert("No Documents Open");
        return;
    }
}

function openImage(filePath, bt) {
    bt.body = psScript.toString() + "\rpsScript('" + filePath + "');";
    bt.onError = function (inBT) {
        alert(inBT.body);
    };
    bt.onResult = function (resObj) {};

    // Wait for Photoshop to be ready
    bt.send(1000);

    function psScript(filePath) {
        app.bringToFront();
        var imageFile = new File(filePath);
        if (imageFile.exists) {
            open(imageFile);
            // Do something
        } else {
            alert("File not found: " + filePath);
        }
    }
}
rob day
Community Expert
Community Expert
February 21, 2024

Also on the script—if you really just want to open the link in Photoshop you don‘t need the BridgeTalk object and extra code. You only need BridgeTalk code when you need to run a Photoshop script on the opened file.

 

This opens the original:

 

if (app.selection.length > 0) {
    var s = app.selection[0]; 
    if (s.constructor.name == "Image") {
        s.itemLink.editOriginal();
    } else {
        alert("Selected item is not an image.");
    }
} else {
    alert("No items selected.");
}
Rene Andritsch
Community Expert
Community Expert
February 20, 2024

You can simply “ALT” click an image to open it in Photoshop. No need for a script.

SesammeAuthor
Inspiring
February 21, 2024
hmmm, click where exactly? I tried to ALT click on the image, on the image box, on the link in the links panel - nothing works. are you sure it works on Mac?
rob day
Community Expert
Community Expert
February 21, 2024

I tried to ALT click on the image

 

Sorry, on a Mac it’s Option- Double-Click with one of the selection tools active—a single click won‘t do it. There’s also Edit>Edit Original, which can be assigned a key command.