@m1b
var link = selectedFrame.images[0].itemLink;
You have to keep that one.
Otherwise it won't update the modified link.
You can't open the current image without updating the modified link.
Try this for your main function:
(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 picture frame');
// 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.LINK_MISSING === item.graphics[0].itemLink.status
)
// ignore anything we can't use
continue;
var link = item.graphics[0].itemLink;
// update the image
if (LinkStatus.LINK_OUT_OF_DATE === link.status)
link.update();
// first linked image is all we need right now
paths.push(link.filePath);
links.push(link);
}
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.');
})();
I have put the update link code in the right place. See if it works.
- Mark
P.S. you may find this function useful to collect links from the selection (or page items):
/** demonstration of GetLinks usage. */
(function () {
var doc = app.activeDocument,
links = getLinks(doc.selection);
alert('links.length = ' + links.length);
for (var i = 0; i < links.length; i++)
$.writeln(links[i].name);
})();
/**
* Get Links from the given `items`.
* @7111211 m1b
* @version 2025-06-25
* @9397041 {Array<PageItem>|collection|PageItem|Image} items - the items to search.
* @Returns {Array<Link>?}
*/
function getLinks(items) {
var links = [];
if ('function' === typeof items.everyItem)
items = items.everyItem().getElements();
if ('Array' !== items.constructor.name)
items = [items];
for (var i = 0, item; i < items.length; i++) {
item = items[i];
if (
item.hasOwnProperty('graphics')
&& 1 === item.graphics.length
&& item.graphics[0].itemLink.isValid
) {
links.push(item.graphics[0].itemLink);
continue;
}
else if (
item.hasOwnProperty('itemLink')
&& item.itemLink.isValid
) {
links.push(item.itemLink);
continue;
}
else if (
item.hasOwnProperty('pageItems')
&& item.pageItems.length > 0
)
links = links.concat(getLinks(item.pageItems) || []);
}
if (links.length)
return links;
};