Skip to main content
joseg95190498
Participant
December 14, 2022
Question

Check if the file opened is a idml file

  • December 14, 2022
  • 1 reply
  • 366 views

Hi guys, I'm tryin to write a jsx script to detect wheter the active document is idml file, if so save it as indd. For that, my first approach is trying to get the fullname of the active document because if it is a idml file will throw an error.

function checkIfDocumentHasFullName(document) {
    try {
        document.fullName;
        return true;
    } catch (e) {
        alert("Some message");
        return false;
    }
}

 But I'm wondering if there could be other scenarios where this could happen as well or maybe other correct way to do this.

Any help much appreciated.

This topic has been closed for replies.

1 reply

Robert at ID-Tasker
Legend
December 14, 2022

Probably, if file been created in the previous version of InDesign and "converted" - then you should have the same error.

 

joseg95190498
Participant
December 14, 2022

 My other huge problem its that I am a complete newbie with InDesign, I'm learning it for work. So thanks a lot for your answer!

rob day
Community Expert
Community Expert
December 14, 2022

Hi @joseg95190498 , If you get the name of a document opened from an .idml it has no extention, but a converted file would, so this might work:

 

 

if (isIDML(app.activeDocument)) {
	alert("This document was opened from an .IDML file")
} else {
    alert("This document was opened from an .INDD file")
}


function isIDML(d) {
    try {
        d.fullName;
        return false;
    } catch (e) {
        var n = d.name.split(".");
        if (n[n.length-1] != "indd") {
            return true;
        } 
    }
}