Skip to main content
Inspiring
July 11, 2023
Question

Cannot create link from the given URI based on the folder Path

  • July 11, 2023
  • 2 replies
  • 148 views

Hi,

I have used the script to get the image link's path. For a month it's working fine in the InDesign previous versions but by using the latest version of InDesign I can't able to retrieve the image path. I have attached the script which I used to retrieve the image path

var doc = app.activeDocument;
// Loop through all the links in the document
  var link = doc.links[0];
  // Get the file path of the linked image
  var filePath = link.filePath;
  // Create a File object from the file path
  var file = new File(filePath);
  // Get the folder path of the file
   folderPath = file.parent.fsName;

 

This topic has been closed for replies.

2 replies

rob day
Community Expert
Community Expert
July 11, 2023

Hi @MonishaRajendran , Did you try checking the returned paths via a $.writeln()? You could simplify with this, but what you have should work.

 

var doc = app.activeDocument;

//a test link on the desktop
var link = doc.links[0];

//link as a file
var file = new File(link.filePath);

//link file’s parent folder
var folderPath = file.parent

$.writeln(file)
//returns ~/Desktop/testlink.png

$.writeln(folderPath)
//returns ~/Desktop

 

Community Expert
July 11, 2023

What are we supposed to understand by "can't able to retrieve the image path"? Please provide more details like

  • Do you get an error? If so what is it?
  • Does it execute but the result is not as per your expectation?
  • Did you try the same code and same Indd file in different versions of InDesign and got different results. If yes then please let us know the InDesign versions and also share the code/indd file to test with.

-Manan

-Manan