Skip to main content
January 18, 2012
Answered

[js][cs4] How do I access a link modified date using a script

  • January 18, 2012
  • 1 reply
  • 909 views

When I interactive check a link's Info, the modified date is Tuesday, January 17, 2012 7:18 but my script returns the date the link was last updated instead of the file's date. For instance it may be yesterday's date even though the file was updated a few minutes ago.

I've tried docRef.links.linkXmp.properties.modificationDate and docRef.links.date but I can't seem to check the link's file date.

I was able to get the date using vb script but I'm wanting to use JSON to information to re-link to different files depending up conditions.

This topic has been closed for replies.
Correct answer

Thank you. I was able to find that answer since I posted the question in the "JavaScrip Tools Guide."

I used:

var file = File (docRef.links.filePath);

I was then able to get the modified date and time by using: "file.modified"

#target indesign
main();
function main() {
if (app.documents.length == 0) {
alert("Please have an 'Indesign' document before running this script.");
return;
}

listLinks(docRef);
};

function listLinks(docRef, myStopCounter) {
     var myCurrentTime = new Date ;
     var myCalculatedMinutes = Date;

     for (var i = docRef.links.length-1; i >= 0; i--) {
           var file = File (docRef.links.filePath);
      if (file.exists)
            alert(docRef.links.name + " - " + DateDiff_inMinutes(myCurrentTime, file.modified), "Link name");
      }// for/*/
}

function DateDiff_inMinutes(/*Date*/ date1, /*Date*/ date2) {     return (date1.getTime() - date2.getTime())/(1000*60); }

1 reply

John Hawkinson
Inspiring
January 18, 2012

I believe you need to construct a new File() object and check its properties.

Correct answer
January 18, 2012

Thank you. I was able to find that answer since I posted the question in the "JavaScrip Tools Guide."

I used:

var file = File (docRef.links.filePath);

I was then able to get the modified date and time by using: "file.modified"

#target indesign
main();
function main() {
if (app.documents.length == 0) {
alert("Please have an 'Indesign' document before running this script.");
return;
}

listLinks(docRef);
};

function listLinks(docRef, myStopCounter) {
     var myCurrentTime = new Date ;
     var myCalculatedMinutes = Date;

     for (var i = docRef.links.length-1; i >= 0; i--) {
           var file = File (docRef.links.filePath);
      if (file.exists)
            alert(docRef.links.name + " - " + DateDiff_inMinutes(myCurrentTime, file.modified), "Link name");
      }// for/*/
}

function DateDiff_inMinutes(/*Date*/ date1, /*Date*/ date2) {     return (date1.getTime() - date2.getTime())/(1000*60); }