I am trying to write a script...
Here you are trying to apply a name to exported file.
myDoc.exportFile(ExportFormat.pdfType, File(Folder.desktop + "/ExportPDFWithPreset.pdf"),false, myPDFExportPreset);
Here is your doc name:
@Jarek – my suggestion to the string that includes the file name without suffix:
var myString = myDoc.name.replace(/\.indd$/i,"");
Just to be save. You never know… ;-)
@Hank – that Regular Expression will only look at the end of the actual name of "myDoc" (the "$" will do that) and will replace ".indd" with an empty string (= deletes it). The parameter "i" is for case insensitive: Strange cases like ".INDD", ".iNdD" etc. are covered.