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

How to solve: images don't update automatically after opening and modifying them in ps with a script

Guide ,
Jun 15, 2025 Jun 15, 2025

Holle! m1b everyone

This script opens the image in Ps, but the image in the ID is not updated after the changes are saved. It's a bit of a workload to update hundreds of images manually.
Is there any way to solve it?

Thank you very much.

I came across this posting and it's a bit too long to read.
another post

699.png

/**
 *  Open Selected Links In Photoshop.js
 *
 * Opens the selected linked file(s) in Photoshop.
 *
 *  m1b
 *  2025-03-08
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-to-open-images-with-different-default-applications-in-indesign-and-resource-manager-windows/m-p/15197180
 */
(function () {

    if (0 === app.documents.length)
        return alert('Please open a document and try again.');

    var doc = app.activeDocument,
        items = doc.selection;

    if (0 === items.length)
        return alert('Please select a linked graphic frame and try again.');

    // collect paths for each selected item
    var paths = [];

    for (var i = 0; i < items.length; i++) {

        var item = items[i];

        // maybe user selected the image, not the frame
        if ('Image' === item.constructor.name)
            item = item.parent;

        if (
            !item.hasOwnProperty('graphics')
            || 0 === item.graphics.length
            || !item.graphics[0].itemLink
            || LinkStatus.NORMAL !== item.graphics[0].itemLink.status
        )
            // ignore anything we can't use
            continue;

        // first linked image is all we need right now
        paths.push(item.graphics[0].itemLink.filePath);

    }

    if (0 === paths.length)
        return alert('Please select a linked graphic frame and try again.');

    // open the paths in photoshop
    openPathsInPhotoshop(paths);

})();

/**
 * Opens the given `paths` in Photoshop.
 *  m1b
 *  2025-03-08
 *  {Array<String>} paths - the paths to open.
 */
function openPathsInPhotoshop(paths) {

    const DELIMITER = '###';

    var photoshop = BridgeTalk.getSpecifier("photoshop");

    if (!photoshop)
        return alert("Photoshop is not available.");

    // send script via BridgeTalk
    var bt = new BridgeTalk();
    bt.target = photoshop;

    // arrange the function inside an IIFE string,
    // and perform string replacements to insert
    // our variables
    bt.body = '(#FN#)("#P#","#D#");'
        .replace('#D#', DELIMITER)
        .replace('#P#', paths.join(DELIMITER))
        .replace('#FN#', openPaths);

    bt.onResult = undefined;
    bt.send(1000);

};

/**
 * Photoshop function to open the given `paths`.
 * Note: cannot use // style comments here because
 * of the way I stringify it.
 *  {String} paths - the paths, delimited.
 *  {String} delimiter - the string used to delimit `paths`.
 */
function openPaths(paths, delimiter) {

    app.bringToFront();

    /* make aray by splitting paths */
    paths = paths.split(delimiter);

    for (var i = 0; i < paths.length; i++)
        if (File(paths[i]).exists)
            app.open(File(paths[i]));

};

 

TOPICS
Bug , Feature request , How to , Scripting
618
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 ,
Jun 15, 2025 Jun 15, 2025

Hi @dublove ,

why do you not relink the placed image after changing it in PhotoShop?

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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 ,
Jun 15, 2025 Jun 15, 2025

@dublove I would do as Uwe suggests, using relink.

 

For your learning, I have written a script based on my original "open in photoshop" script but now it opens, edits (adds "DEMO" text) saves as .psd, then relinks.

- Mark

 

/**
 * @file Edit Selected Graphics In Photoshop.js
 *
 * Does the following:
 *   1. opens the selected graphic(s) in Photoshop
 *   2. adds a "DEMO" watermark text
 *   3. saves them as psd files to the same folder
 *   4. back in Indesign, relinks to the new psd files.
 *
 * @author m1b
 * @version 2025-06-15
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-to-solve-images-don-t-update-automatically-after-opening-and-modifying-them-in-ps-with-a-script/m-p/15370844#M628200
 */
function main() {

    if (0 === app.documents.length)
        return alert('Please open a document and try again.');

    var doc = app.activeDocument,
        items = doc.selection;

    if (0 === items.length)
        return alert('Please select a linked graphic frame and try again.');

    // collect paths for each selected item
    var sourcePaths = [],
        destinationPaths = [],
        links = [];

    for (var i = 0; i < items.length; i++) {

        var item = items[i];

        // maybe user selected the image, not the frame
        if ('Image' === item.constructor.name)
            item = item.parent;

        if (
            !item.hasOwnProperty('graphics')
            || 0 === item.graphics.length
            || !item.graphics[0].itemLink
            || LinkStatus.NORMAL !== item.graphics[0].itemLink.status
        )
            // ignore anything we can't use
            continue;

        sourcePaths.push(item.graphics[0].itemLink.filePath);
        destinationPaths.push(item.graphics[0].itemLink.filePath.replace(/\.[^\.]+$/, '_demo.psd'),);
        links.push(item.graphics[0].itemLink);

    }

    if (0 === sourcePaths.length)
        return alert('Please select a linked graphic frame and try again.');

    // open the paths in photoshop
    editImages(sourcePaths, destinationPaths, updateLinks(links));

    /**
     * Returns a callback function that updates `links`.
     * @param {Array<Link>} links - the links to update.
     */
    function updateLinks(links) {

        return function callback() {

            // update each link
            for (var i = 0; i < links.length; i++)
                links[i].relink(File(destinationPaths[i]));

        }; // end returned callback

    };

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Edit Selected Graphics');

/**
 * Edits the graphics found at `sourcePaths` in Photoshop,
 * and saves them as layered psd documents.
 * @author m1b
 * @version 2025-06-15
 * @param {Array<String>} sourcePaths - the paths to open.
 * @param {Array<String>} destinationPaths - the paths to save into.
 */
function editImages(sourcePaths, destinationPaths, callback) {

    const DELIMITER = '###';

    var photoshop = BridgeTalk.getSpecifier("photoshop");

    if (!photoshop)
        return alert("BridgeTalk couldn\'t find Photoshop.");

    // send script via BridgeTalk
    var bt = new BridgeTalk();
    bt.target = photoshop;

    // arrange the function inside an IIFE string,
    // and perform string replacements to insert
    // our variables
    bt.body = '(#FUNC#)("#SRC#","#DST#","#DLM#");'
        .replace('#FUNC#', editImagesInPhotoshop)
        .replace('#SRC#', sourcePaths.join(DELIMITER))
        .replace('#DST#', destinationPaths.join(DELIMITER))
        .replace('#DLM#', DELIMITER);

    bt.onResult = callback;
    bt.send(1000);

};

/**
 * Photoshop function to open the `sourcePaths`, add a
 * demo watermark, and save them as layered .psd files.
 * Note: we cannot use // style comments here because
 * of the way I stringify it.
 * @author m1b
 * @version 2025-06-15
 * @param {String} sourcePaths - the paths, delimited.
 * @param {String} delimiter - the string used to delimit `paths`.
 */
function editImagesInPhotoshop(sourcePaths, destinationPaths, delimiter) {

    // app.bringToFront();

    /* make aray by splitting paths */
    sourcePaths = sourcePaths.split(delimiter);
    destinationPaths = destinationPaths.split(delimiter);

    for (var i = 0; i < sourcePaths.length; i++) {

        if (!File(sourcePaths[i]).exists)
            continue;

        var doc = app.open(File(sourcePaths[i]));

        /* just for a demo, adds the word "demo" */
        demo(doc);

        /* save as psd */
        var psdSaveOptions = new PhotoshopSaveOptions();
        doc.saveAs(File(destinationPaths[i]), psdSaveOptions, true);
        doc.close(SaveOptions.DONOTSAVECHANGES);

    }

    /**
     * Add a centered "DEMO" text layer, sized to document width.
     * @param {Document} doc - a photoshop document.
     */
    function demo(doc) {

        var targetWidth = doc.width.as('px') * 0.9;

        var layer = doc.artLayers.add();
        layer.kind = LayerKind.TEXT;
        layer.opacity = 30;

        var text = layer.textItem;
        text.contents = 'DEMO';
        text.position = [doc.width.as('px') / 2, doc.height.as('px') / 2];
        text.justification = Justification.CENTER;
        text.size = 100;

        var widthA = layer.bounds[2] - layer.bounds[0];
        text.size = 1000;
        var widthB = layer.bounds[2] - layer.bounds[0];
        text.size = 10 + ((widthA - targetWidth) * (1000 - 10) / (widthA - widthB));
        text.position = [doc.width.as('px') / 2, (doc.height.as('px') + (layer.bounds[3] - layer.bounds[1])) / 2];

    };

};
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 ,
Jun 15, 2025 Jun 15, 2025

Hi @m1b 

Thank you very much.
I'll look into it, but I have a feeling you're not understanding what is my The question of real requests.
Maybe I just need some part of this script.

 

What I'm talking about is, by the original default: we hold down Alt, while double clicking on the image, the image opens in ps, we modify the image and save it, and the ID automatically updates the link.

But a picture opened with a script will not automatically update the link after modification.

 

I don't need to change the format of the original image.
I think changing the original image format and then relinking it. That should be another script that may be very necessary at times.
For the image re-linking to another format, I've seen that script, and I'd prefer that script to pop up the talk box for me to manually select which format to link to.

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 ,
Jun 15, 2025 Jun 15, 2025

but I have a feeling you're not understanding

 

Hi @dublove , The  reason that your code doesn’t update the image is the script ends as the link opens and before you can make any changes. Add an alert at the end of the openPaths() function and you will see that the script is completed before you make any changes.

 

 

 

 

/**
 * Photoshop function to open the given `paths`.
 * Note: cannot use // style comments here because
 * of the way I stringify it.
 *  {String} paths - the paths, delimited.
 *  {String} delimiter - the string used to delimit `paths`.
 */
function openPaths(paths, delimiter) {

    app.bringToFront();

    /* make aray by splitting paths */
    paths = paths.split(delimiter);

    for (var i = 0; i < paths.length; i++)
        if (File(paths[i]).exists)
            app.open(File(paths[i]));

            alert("Scipt Finished")

};
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 ,
Jun 15, 2025 Jun 15, 2025

Also, the script is not using the Edit Original menu command, which might be what you are looking for?

 

You can invoke the Edit Original menu command via menuActions invoke(). I don’t think a BridgeTalk open will work because it is the same as opening files from the finder.

 

If you script the Photoshop edits as @Laubender and @m1b suggest, then you can do the updates on a call back to InDesign after the Photoshop scipted edits.

 

And why do you even need a script, can’t you simply select the Links you need to edit in the panel and use Edit Original? That will open the selected Links and update them after you save the edits in PS :

 

Screen Shot 25.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
Guide ,
Jun 16, 2025 Jun 16, 2025

Hi rob day.

Edit the original?
This has been assigned to an image quick viewer (like HoneyView.exe)

Theoretically you can only update the image with a trigger wait.
But the ID default seems to be that switching back to the InDesign window is considered updating the just-opened image again.

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 ,
Jun 15, 2025 Jun 15, 2025

For example:
InDesign listens for the image aaa.jpg to be opened.
During this time, changes may be made manually in ps, unsure of what time it will end.
Until it listens for aaa.jpg to be stored, the auto-update command is executed.

 

That's what is supposed to be using , when you double-click on Alt in ID and then open it in ps.

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 ,
Jun 15, 2025 Jun 15, 2025

I tried to just add the following before the function openPath() in the script I posted:

From this
var linkURI = link.linkResourceURI;
an error sound is prompted.

There is no text message about the error.

 

var selectedFrame = app.selection[0];
var link = selectedFrame.images[0].itemLink;
var linkURI = link.linkResourceURI;
link.reinitLink(linkURI);
var done = false,
counter = 0;

var selectedFrame = app.selection[0];
var link = selectedFrame.images[0].itemLink;
while (!done && counter++ < 10) {
try {
$.sleep(1000);
if (LinkStatus.LINK_OUT_OF_DATE === link.status) {
link.update();
done = true;
};
} catch (error) { }
}

 

 

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 ,
Jun 15, 2025 Jun 15, 2025

Hi @dublove you are right that I didn't understand what you wanted. How about this? It will get Indesign to ask you when the graphics have been updated and then perform the update on any that have changed.

 

There are other approaches, but this is the simplest.

- Mark

 

/**
 * @file Open Selected Graphics In Photoshop.js
 *
 * Opens the selected linked file(s) in Photoshop,
 * waits for them to be re-saved and then updates them.
 *
 * @author m1b
 * @version 2025-06-16
 * @discussion https://community.adobe.com/t5/indesign-discussions/how-to-solve-images-don-t-update-automatically-after-opening-and-modifying-them-in-ps-with-a-script/m-p/15370844
 */
(function () {

    if (0 === app.documents.length)
        return alert('Please open a document and try again.');

    var doc = app.activeDocument,
        items = doc.selection;

    if (0 === items.length)
        return alert('Please select a linked graphic frame and try again.');

    // collect paths for each selected item
    var paths = [],
        links = [];

    for (var i = 0; i < items.length; i++) {

        var item = items[i];

        // maybe user selected the image, not the frame
        if ('Image' === item.constructor.name)
            item = item.parent;

        if (
            !item.hasOwnProperty('graphics')
            || 0 === item.graphics.length
            || !item.graphics[0].itemLink
            || LinkStatus.NORMAL !== item.graphics[0].itemLink.status
        )
            // ignore anything we can't use
            continue;

        // first linked image is all we need right now
        paths.push(item.graphics[0].itemLink.filePath);
        links.push(item.graphics[0].itemLink);
    }

    if (0 === paths.length)
        return alert('Please select a linked graphic frame and try again.');

    // open the paths in photoshop
    openPathsInPhotoshop(paths);

    if (!confirm('Are you ready to update the selected graphics?'))
        return;

    var counter = 0;

    for (var i = links.length - 1; i >= 0; i--) {

        if (LinkStatus.LINK_OUT_OF_DATE !== links[i].status)
            continue;

        links[i].update();
        counter++;

    }

    alert('Updated ' + counter + ' graphics.');

})();

/**
 * Opens the given `paths` in Photoshop.
 * @author m1b
 * @version 2025-03-08
 * @param {Array<String>} paths - the paths to open.
 */
function openPathsInPhotoshop(paths) {

    const DELIMITER = '###';

    var photoshop = BridgeTalk.getSpecifier("photoshop");

    if (!photoshop)
        return alert("BridgeTalk couldn\'t find Photoshop.");

    // send script via BridgeTalk
    var bt = new BridgeTalk();
    bt.target = photoshop;

    // arrange the function inside an IIFE string,
    // and perform string replacements to insert
    // our variables
    bt.body = '(#FN#)("#P#","#D#");'
        .replace('#D#', DELIMITER)
        .replace('#P#', paths.join(DELIMITER))
        .replace('#FN#', openPaths);

    bt.onResult = undefined;
    bt.send(1000);

};

/**
 * Photoshop function to open the given `paths`.
 * Note: cannot use // style comments here because
 * of the way I stringify it.
 * @param {String} paths - the paths, delimited.
 * @param {String} delimiter - the string used to delimit `paths`.
 */
function openPaths(paths, delimiter) {

    app.bringToFront();

    /* make aray by splitting paths */
    paths = paths.split(delimiter);

    for (var i = 0; i < paths.length; i++)
        if (File(paths[i]).exists)
            app.open(File(paths[i]));

};

 

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 ,
Jun 15, 2025 Jun 15, 2025

Hi @m1b 

Thank you very much.

No need to confirm the update.
When PS saves and then switches to the ID software, it should be updated.
Just update it silently, ID does the same by default, switch back to the ID window and it's updated.

 

Also after the image is modified, if you don't update the link, you can't use the script to open this not very friendly.

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 ,
Jun 15, 2025 Jun 15, 2025
confirm("");

Can this not pop up and be confirmed by default?

alert('Updated ' + counter + ' graphics.');

Are these two sentences a manual trigger wait?

That doesn't seem like the best way to do it.

 

ID updates links by default, the principle may be:
It should be that when you switch back to the ID window again, it assumes that you confirmed updating the link to the image you just opened.

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 ,
Jun 16, 2025 Jun 16, 2025

Hi @dublove you do not understand the architecture, and unfortunately this is a complex topic to grasp. But I will try to explain what is happening in the script:

 

Script A: main script in Indesign

1. Script collects the paths from the selected graphics.

2. Sends a BridgeTalk message to Photoshop to open files at those paths.

3. Shows confirm dialog to keep the script paused while you make the edits.

4. Update any links that have been modified.

5. End

 

Script B: BridgeTalk-spawned script in Photoshop 

(this executes before step 3 in script A)

1. Open files at the given paths.

2. End

 

Notes:

• If we remove step 3 from script A, then step 4 won't find any modified links becaues you won't have done any editing yet.

• We could use $.sleep(N) where N milliseconds is greater than the time it takes you to finish editing and saving the files in photoshop. Of course that is not practical.

• Your expectation that the images update automatically when returning to Indesign is a nice thought, but there is no way to do that well in my opinion.

 

My suggestion: run a separate script for updating those images. Would that work for you?

- Mark

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 ,
Jun 16, 2025 Jun 16, 2025

Hi  m1b~

Thanks so much.

I seem to be stuck in the mud again.

 

In ID, pressing Alt and double clicking to open the image really does update it automatically after modifying it in ps.
I guess it works like this: when the Indesign window on the taskbar is activated again, it updates the image that has just been modified.

 

It would also be very nice to keep the following dialog box from popping up.
Make it select "Yes" by default.

if (!confirm('Are you ready to update the selected graphics?'))
return;


Keep only the last prompt.

 

Also, is it possible to get the unchanged path so that the image will open without updating the link.

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 ,
Jun 24, 2025 Jun 24, 2025
LATEST

> It would also be very nice to keep the following dialog box from popping up. Make it select "Yes" by default.

 

This shows that you did not carefully read the order of operations. Without this confirm dialog pausing the script there is no point to check if the images need updating, because you won't have had time to edit them yet.

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