Skip to main content
dublove
Legend
April 28, 2026
Question

Is there a way to keep the image selected after it's updated?

  • April 28, 2026
  • 1 reply
  • 15 views

It seems like the focus is lost after the update.

I was hoping for a simpler solution:

if (app.selection[0].constructor.name == “Image”) {
var image = app.activeDocument.selection[0];
var imagePath = image.itemLink.filePath;
}
if (LinkStatus.LINK_OUT_OF_DATE === image.status) {
image.update();
}

But I didn’t quite understand what the body of ‘update()’ was supposed to be. Later, I found the code snippet below, but while it updates the image, the focus is lost and the code doesn’t continue. It seems it needs to keep the selection.


var graphics = getGraphics(doc.selection);
// Create paths and link objects
var paths = [];
var links = [];
for (var i = 0; i < graphics.length; i++) {
if (graphics[i].hasOwnProperty(‘itemLink’))
paths.push(graphics[i].itemLink.filePath);
links.push(graphics[i].itemLink);
}
if (0 === paths.length)
alert(‘Image appears to be missing!’);
for (i = 0; i < links.length; i++) {
if (LinkStatus.LINK_OUT_OF_DATE === links[i].status) {
links[i].update();
}
}


/**
* Returns graphics derived from `items`.
* @author m1b
* @version 2025-08-20
* @param {Array|PageItem} items - array or collection or page item.
*/
function getGraphics(items) {
var graphics = [];
if ('Array' === items.constructor.name) {
for (var i = 0; i < items.length; i++)
graphics = graphics.concat(getGraphics(items[i]));
}

else if (
items.hasOwnProperty('allGraphics')
&& items.allGraphics.length > 0
)
graphics = graphics.concat(items.allGraphics);
else if (
items.hasOwnProperty('allPageItems')
&& items.allPageItems.length > 0
)
graphics = graphics.concat(getGraphics(items.allGraphics));
else if ('Image' === items.constructor.name) {
graphics.push(items);
}
return graphics;
};

 

    1 reply

    rob day
    Community Expert
    Community Expert
    April 28, 2026

    Assuming the selection is a linked image:

     

    var d = app.activeDocument;
    var s = d.selection[0]
    //get the selected image’s itemLink (link object)
    var l = s.itemLink
    //if the link’s status is modified update
    if (l.status === LinkStatus.LINK_OUT_OF_DATE) {
    l.update()
    //use l.parent if you want to reselect
    d.select(l.parent)
    }