Copy link to clipboard
Copied
Sometimes, it is necessary to switch to the direct selection tool (white arrow) in order to recognize it.
Sometimes, it is again necessary to use the selection tool (black arrow) to recognize it.
For example:
// open the paths in photoshop
openPathsInPhotoshop(paths);
This requires the selection tool.
If it is a direct selection tool, it will report an error.
Is it possible to pass through?
Because sometimes we don't need to distinguish between them.
Thank you very much.
I think you need a function to check your selection for an image, something like this:
main()
function main(){
//if checkSelection() returns no image send alert and stop the script
if (checkSelection() == undefined) {
alert("No Image Selected")
return
}
//get the file path
var fp = checkSelection()
alert("This selection’s file path: " + fp)
}
/**
* Checks if a selection is an image or contains an image
* @ return the image file path
*/
function c
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,
...
Copy link to clipboard
Copied
Something like the following would work. Make a selection with either the direct selection tool or selection tool and execute the following code
var sel = app.selection[0]
if (sel.hasOwnProperty("itemLink")) {
alert(sel.itemLink.filePath)
}
else if (sel.hasOwnProperty("graphics")) {
if(sel.graphics.length)
alert(sel.graphics[0].itemLink.filePath)
}
-Manan
Copy link to clipboard
Copied
Hi Manan Joshi
Not sure how to use this piece of your code, the error reported above may be caused by the one below.
//update links
var selectedFrame = app.selection[0];
var link = selectedFrame.images[0].itemLink;
if (LinkStatus.LINK_OUT_OF_DATE === link.status)
link.update();
It was originally at the top.
I was just happy for a moment, and then the same problem happened again.
Putting it on the back still causes problems.
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.');
//update links
var selectedFrame = app.selection[0];
var link = selectedFrame.images[0].itemLink;
if (LinkStatus.LINK_OUT_OF_DATE === link.status)
link.update();
Copy link to clipboard
Copied
I cannot reproduce your issue using the direct selection tool. It works as normal.
Maybe you could try running this script when you have the selection, and it might reveal something...
alert(app.activeDocument.selection[0].constructor.name);
Copy link to clipboard
Copied
I saw what you originally said. You can wait a certain amount of time and update the link.
That should be a no-brainer but doable, too. There Most images, if stored within 20 seconds update. If it times out it doesn't matter.
Seems to be this posting. How is it implemented?
https://community.adobe.com/t5/indesign-discussions/how-to-solve-images-don-t-update-automatically-a... them-in-ps-with-a-script/m-p/15370844
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Your image could be below the current selection:
Alert code
var ag = app.activeDocument.selection[0].allGraphics
alert("The selected item contains " + ag.length + " graphics");
Copy link to clipboard
Copied
Also you can select the placed object via the Links panel’s Go To Link
Copy link to clipboard
Copied
Hi @rob day
My question now is:
How do I get both black and white arrows to work.
Copy link to clipboard
Copied
Share an example where it’s not working.
Copy link to clipboard
Copied
Except that you can't use the direct selection tool.
This one is probably the one that can determine the most exceptions (missing images, links not updated, no images selected)
Can you add the indistinguishable selection tool?
Also, countdown to 20 seconds to update the link.
/**
* @original author m1b
* @version 2025-06-16
* @original 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
Current address:
https://community.adobe.com/t5/indesign-discussions/how-to-get-the-image-path-without-switching-the-selection-tool/m-p/15385688#M629189
**/
(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');
var selectedFrame = app.selection[0];
var imageFile = new File(selectedFrame.images[0].itemLink.filePath);
if (!imageFile.exists)
alert("Current file does not exist", 600);
//update
var selectedFrame = app.selection[0];
var link = selectedFrame.images[0].itemLink;
if (LinkStatus.LINK_OUT_OF_DATE === link.status)
link.update();
// 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.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);
links.push(item.graphics[0].itemLink);
}
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.');
})();
/**
* Opens the given `paths` in Photoshop.
* @author m1b
* @version 2025-03-08
* @param {Array<String>} paths - the paths to open.
*/
function openPathsInPhotoshop(paths) {
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 = '(#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.
* @param {String} paths - the paths, delimited.
* @param {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]));
};
Copy link to clipboard
Copied
@dublove the problem in this case is that in this line
var link = selectedFrame.images[0].itemLink;
you expect to have a frame but sometimes it might be a graphic in a frame. (Nothing to do with direct selection tool, just depends what you've got selected: the frame or the graphic.
That's why in my code I did this:
// maybe user selected the image, not the frame
if ('Image' === item.constructor.name)
item = item.parent;
This makes sure that the item is always the frame, never the graphic.
- Mark
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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`.
* @author m1b
* @version 2025-06-25
* @Param {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;
};
Copy link to clipboard
Copied
Hi m1b.
Thank you very much.
You're so great.
That's what it means.
You work normally, it will automatically update previous links, it will prompt for not selecting normally, and the black and white arrows work normally.
You are so great.
Copy link to clipboard
Copied
Note that my colleagues are giving you the same information and are perfectly correct. My advantage is that I wrote the script you are modifying so it was easier for you to incorporate my version.
- Mark
Copy link to clipboard
Copied
Is it possible to simulate the menu method to open the image
This will update automatically.
It will also not change the default application honeview for images in windows.
Copy link to clipboard
Copied
I don't know how to similar that menu. I think we only have access to the non-dynamic menus, eg. "Edit Original". But that will open in honeyview, so no good for your case.
Copy link to clipboard
Copied
The search on Adobe's site is kind of bad.
I remember a posting where you guys discussed countdown updates.
I've searched and can't find it.
I think waiting 30 seconds for an update might be acceptable.
Copy link to clipboard
Copied
Try searching for IdleTask. It isn't for the faint-hearted though.
Copy link to clipboard
Copied
Hi @dublove ,
that's more than unusual, that you need the Direct Selection tool.
Please attach a sample InDesign document where this is the case.
Thanks,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Hi @dublove ,
thank you for your sample InDesign document test.indd in zip test-6-24.zip.
I ran the following code on the selected upper rectangle without any issue:
var itemLink = app.selection[0].images[0].itemLink;
alert( File( itemLink.filePath).fsName );
Also successfully when I selected the bottom frame:
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Do you try it with the direct selection tool (white arrow) and does it pop up an error?
It might be somewhat useful for you to have this pop up a hint, for the missing diagram, copy the original path to the clipboard:
Path copied to clipboard
Copy link to clipboard
Copied
@dublove asked: "… Do you try it with the direct selection tool (white arrow) and does it pop up an error?"
Not yet. What you see from my screenshots are selections with the Selection tool and not with the Direct Selection tool. Using the Direct Selection tool makes no sense to me. And it makes no difference if you do it right:
Note the selected path and the path points showing up when using the Direct Selection tool.
So you need to select the edge of the frame to select the frame itself with the Direct Selection tool. If you click inside the frame you select the image inside the frame. And that, of course, leads to an error with my little code snippet:
So yes, it makes a difference how you select something.
Regards,
Uwe Laubender
( Adobe Community Expert )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now