I'm not sure why it's not working maybe @m1b has an idea - sorry I know there's more scripters but the handles are escaping me to tag them.
@Eugene Tyson this is an example of how I like to handle BridgeTalk calls. I write a function that I then convert to string using `Function.toSource()` then I call it inside an IIFE, adding parameters to the IIFE call (these must be strings too). (Edit: note that I don't actually invoke `toSource`—the function `openPaths` is impicitly coerced to a string by the `replace` method I used to construct the bt.body string.) This might seem a bit opaque at first but for me it avoids a lot of the messy string concatenation dance that goes on. It also means that I can literally test the Photoshop function `openPaths` directly in photoshop to make sure it works!
@dublove this is my attempt at a script to "Open Selected Images in Photoshop". It works for me on MacOS. Does it work for you on Windows?
- Mark
/**
* @file Open Selected Links In Photoshop.js
*
* Opens the selected linked file(s) in Photoshop.
*
* @author m1b
* @version 2025-03-08
* @discussion https://community.adobe.com/t5/indesign-discussions/how-to-open-images-with-different-default-applications-in-indesign-and-resource-manager-windows/m-p/15197180
*/
(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 linked graphic frame and try again.');
// collect paths for each selected item
var paths = [];
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);
}
if (0 === paths.length)
return alert('Please select a linked graphic frame and try again.');
// open the paths in photoshop
openPathsInPhotoshop(paths);
})();
/**
* 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("Photoshop is not available.");
// 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]));
};
Edit 2025-03-08: fixed a bug, where I forgot to include the string delimiter. Oops!