Skip to main content
dublove
Legend
April 28, 2026
Answered

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

  • April 28, 2026
  • 2 replies
  • 86 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;
};

 

    Correct answer rob day

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

     

    2 replies

    dublove
    dubloveAuthor
    Legend
    April 29, 2026

    Is it possible?

    rob day
    Community Expert
    Community Expert
    April 29, 2026

    You would have to create a text frame, set its contents to the filePath, select the text, copy, and delete the frame. 

    dublove
    dubloveAuthor
    Legend
    April 29, 2026

    Isn't this too complicated.
    That's not very scientific.
    Convert the path to a string and let the clipboard obtain the string.

    Mabe like this:

    var linPath=[];

    linkPath.push(imagePath)

    It seems there are other commands. I'll search some more.

    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    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)
    }

     

    dublove
    dubloveAuthor
    Legend
    April 29, 2026

    Hi ​@rob day 

    Thank you very much.

    How do I copy the image path to the clipboard? I want to add this line:
    I tried doing it this way, but it seems like I copied the image itself, not the path.

    if (l.status === LinkStatus.LINK_MISSING) {
    alert(‘Image missing!’);
    // Copy the link path
    //copy(imagePath);
    app.copy(imagePath)
    exit();
        }

     

    rob day
    Community Expert
    Community Expert
    April 29, 2026

    app.copy() copies the selection in the active document window to the clipboard—the copy() method doesn’t take a parameter. If the image is selected, app.copy() would copy the actual image not its file path