Skip to main content
dublove
Legend
Apr 28, 2026 4:23 PM UTC
Answered

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

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

 

    rob day
    rob dayCorrect answer
    Community Expert
    Apr 28, 2026 9:13 PM UTC

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

     

    10 replies

    dublove
    dubloveAuthor
    Legend
    Apr 29, 2026 1:54 PM UTC

    Is it possible?

    Translate
    rob day
    Community Expert
    Community Expert
    Apr 29, 2026 2:14 PM UTC

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

    Translate
    dublove
    dubloveAuthor
    Legend
    Apr 29, 2026 2:57 PM UTC

    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.

    Translate
    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    Apr 28, 2026 9:13 PM UTC

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

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Apr 29, 2026 3:36 AM UTC

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

     

    Translate
    rob day
    Community Expert
    Community Expert
    Apr 29, 2026 12:15 PM UTC

    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

     

     

    Translate