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

Script that opens a selected InDesign image in Photoshop

Participant ,
Feb 19, 2024 Feb 19, 2024

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);
    }
}

 

TOPICS
Scripting
1.4K
Translate
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 ,
Feb 20, 2024 Feb 20, 2024

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

Translate
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
Participant ,
Feb 21, 2024 Feb 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?
Translate
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 ,
Feb 21, 2024 Feb 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.

 

Screen Shot 12.png

Translate
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
Participant ,
Feb 21, 2024 Feb 21, 2024

Got it! But it only opens the image in the default app, which is not Photoshop for most types of images. This means I need to change all my images to open in Photoshop by default - really wouldn't want to do that 🙂 This is the reason why these sctipts exist.

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

You only have to change it once for an image type like png, jpg, tiff etc.

Translate
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 ,
Feb 22, 2024 Feb 22, 2024

But it only opens the image in the default app

 

On MacOS you can set default file associations from the Finder. Get Info on a PNG or other image format and there is an option to choose which app opens the file by default.

 

Screen Shot 13.png

Translate
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
Participant ,
Feb 23, 2024 Feb 23, 2024

This is not a solution and totally counterproductive, I don't need any of these images to open in Photoshop by default, and I know how to do it. Anyway - I have a working sctipt, and it's great, so no need for that anyway.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Control or Right-Click > Edit With > Photoshop

Translate
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
Participant ,
Feb 25, 2024 Feb 25, 2024

Thats too much clicking - I need a shortcut. Unfortunately it's impossible to attach shortcuts to the native Edit With command.

Translate
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 ,
Feb 20, 2024 Feb 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()
    }  
};
Translate
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
Participant ,
Feb 21, 2024 Feb 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);
        }
    }
}
Translate
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 ,
Feb 21, 2024 Feb 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.");
}
Translate
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
Participant ,
Apr 07, 2024 Apr 07, 2024

again - this only opens the file with whatever app is associated with it - not Photoshop specifically. For this I don't need a sctipt - it's already built into InDesign

Translate
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
Guide ,
Mar 05, 2025 Mar 05, 2025

HI @rob day @Sesamme @Peter Spier @

How not to have to distinguish between black and white arrow choices.
The distinction sometimes adds to the hassle.
More often than not we use black arrows.

 

In fact, this code still doesn't open in PS ......
Rather, it opens in the default application in windows.

 

Thanks.

Translate
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
Guide ,
Mar 08, 2025 Mar 08, 2025
LATEST

@rob day 

I was the one who made the mistake.


This one still only opens images in the windows default app.

And can it be changed to not differentiate between "Selection Tool" and "Direct Selection Tool"versions?

Translate
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 ,
Mar 05, 2025 Mar 05, 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).

Translate
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 ,
Mar 05, 2025 Mar 05, 2025
Translate
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