Skip to main content
dublove
Legend
June 15, 2025
Question

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

  • June 15, 2025
  • 2 replies
  • 701 views

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

/**
 *  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]));

};

 

2 replies

m1b
Community Expert
Community Expert
June 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];

    };

};
dublove
dubloveAuthor
Legend
June 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) { }
}

 

 

dublove
dubloveAuthor
Legend
June 16, 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]));

};

 


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.

Community Expert
June 15, 2025

Hi @dublove ,

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

 

Regards,
Uwe Laubender
( Adobe Community Expert )