Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

scripts

New Here ,
Oct 16, 2023 Oct 16, 2023

Hi, i have a script in InDesign, this script automatically creates an idml file from the document, how can I automate it so that it opens automatically with every document without starting it manually. Thanks a lot

TOPICS
Scripting
979
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2023 Oct 16, 2023

@Bruno Ferdigg 

 

I've moved your post from Creative Cloud Desktop to the InDesign forum and added the topic for Scripting for you.

 

Jane

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 16, 2023 Oct 16, 2023

It should be set up as an "onOpen" event - but I'm not JS guy so you need to wait for someone else for exact JS code. 

 

But why do you need to do this every time you open INDD file? 

A bit strange... Would make more sense on closing / saving INDD file - kind of extra backup? 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2023 Oct 16, 2023

Hi @Bruno Ferdigg 

 

Please choose the folder with INDD files.

var myFileLocation = Folder.selectDialog("Please select path to files"); // file path selection

myFolder = new Folder ([myFileLocation]);

myFolderContents = myFolder.getFiles("*.indd"); // array

myFileAmount = (myFolderContents.length - 1);

// ===== Open, Export as PDF, and Close files ===== \\

for (i = myFileAmount; i >= 0; i--)

{

app.open(File (myFolderContents[i]));

app.activeDocument.exportFile(

ExportFormat.INDESIGN_MARKUP,

new File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".idml"),

false);

app.activeDocument.close(SaveOptions.no);

}

alert("IDML Created")



Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 16, 2023 Oct 16, 2023

@Anantha Prabu G 

You missed the point - OP wants to export IDML every time INDD file is open - not a folder full of INDD files. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2023 Oct 16, 2023

YES. I got it.

Every time we open the INDD files it should be saved as an IDML file as backup.

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2023 Oct 16, 2023

Can you post the script you're working with? Probably just a matter of using app.open(file) somewhere. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 17, 2023 Oct 17, 2023

Hey, this is the script. thnx

  1. //InxAfterSafe.jsx
    #targetengine "session"
    main();

    function main()
    {
    var myEventListener1 = app.addEventListener("afterSave", IDML_Export, false);
    var myEventListener2 = app.addEventListener("afterSaveAs", IDML_Export, false);
    }

    function IDML_Export()
    {
    var myFileName = app.activeDocument.fullName.fullName.replace(/\.indd$/i, "") + ".idml";
    app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, File(myFileName));
    }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 23, 2023 Oct 23, 2023

@brian_p_dts can you help me?? thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 23, 2023 Oct 23, 2023

Hope this helps to you.

#target indesign

 

var myEventListener = app.addEventListener("afterSave", myAfterSaveFunction);

 

function myAfterSaveFunction(myEvent) {

var savedDoc = myEvent.parent;

 

// Check if the saved document is an InDesign document

if (savedDoc instanceof Document) {

// Define the IDML file path

var idmlFilePath = savedDoc.filePath + "/" + savedDoc.name.replace(/\.[^\.]+$/, "") + ".idml";

 

// Export the document to IDML format

savedDoc.exportFile(ExportFormat.INDESIGN_MARKUP, File(idmlFilePath));

alert("IDML file created successfully: " + idmlFilePath);

}

}

 

 

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2023 Oct 23, 2023

I think alert() at the end of the event is rather unnecessary? 

 

And OP needs it onOpen. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2023 Oct 23, 2023

Something like this? If I understand, you want to open the IDML after export. Of course, since this is a startup script, if you then save the exported idml again, it will trigger a new version. 

 

#targetengine "session"
main();

function main()
{
var myEventListener1 = app.addEventListener("afterSave", IDML_Export, false);
var myEventListener2 = app.addEventListener("afterSaveAs", IDML_Export, false);
}

function IDML_Export()
{
try {
var myFileName = app.activeDocument.fullName.fullName.replace(/\.indd$/i, "") + ".idml";
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, File(myFileName));
app.open(File(myFileName));
} catch(e) {}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 25, 2023 Oct 25, 2023
LATEST

I actually just want to automatically save the .idml file for every InDesign document and the script should start when the program InDesign starts. I want to do this because my work colleagues don't have the latest version of InDesign and I do. Without the .idml file they can't open my files, I usually forget to save the .idml file and would like to automate this. Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines