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

Script that opens a selected InDesign image in Photoshop

Participant ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

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

Views

513

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 ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

Control or Right-Click > Edit With > Photoshop

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

Copy link to clipboard

Copied

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

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 ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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
Participant ,
Apr 07, 2024 Apr 07, 2024

Copy link to clipboard

Copied

LATEST

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

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