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

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.

rob day
Community Expert
Community Expert
June 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")

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