Need help with a script
Hi, I wrote a script with which I could open a selected image in AdobeInDesign 2023 in Photoshop, and if the folder containing the image had the same file but with the psd extension, it would open it. If not, then the image I selected was opened. This worked fine on the windows operating system, but I bought a macbook with a m1 processor on Sonoma 14.2.1. As I understand it, the macbook system works differently and now my script doesn't work at all. Please help me rewrite the script so that it works correctly, I really need it for work. Please
Here is the code
#target indesign
var doc = app.activeDocument;
var selection = app.selection[0];
if (selection && selection.constructor.name === "Rectangle" && selection.graphics.length > 0) {
var graphic = selection.graphics[0];
if (graphic.itemLink) {
var filePath = graphic.itemLink.filePath;
var fileFolder = new Folder(filePath).parent;
var baseFileName = filePath.substr(0, filePath.lastIndexOf('.'));
var psdFilePath = baseFileName + ".psd";
var psdFile = new File(psdFilePath);
if (psdFile.exists) {
openInPhotoshop(psdFilePath);
} else {
openInPhotoshop(filePath);
}
} else {
alert("Графічний об'єкт не має посилання на файл.");
}
} else {
alert("Виберіть прямокутник з графічним об'єктом.");
}
function openInPhotoshop(filePath) {
var bt = new BridgeTalk();
bt.target = "photoshop";
// Відкриваємо файл
bt.body = "app.open(new File('" + filePath + "'));";
bt.body += "app.bringToFront();"; // Виводимо Photoshop на передній план
// Для macOS
if ($.os.indexOf("Mac") > -1) {
bt.body += "var appFile = new File(app.path + '/' + app.name);";
bt.body += "app.system('open \"' + appFile.fsName + '\"');";
}
bt.onResult = function(resultMsg) {
$.sleep(1000); // Чекаємо секунду, щоб дати час Photoshop відкритися
app.activate(); // Повертаємо фокус на InDesign
};
bt.onError = function(errorMsg) {
alert("Помилка при відкритті файлу в Photoshop: " + errorMsg);
};
bt.send();
}
