File export wait for 2 sec issue

Hi all, I am using below code to export the activeDoc but I have to wait for 2 sec to read that exported file.

Is there any other way to export the file? so I do not have to wait for 2 sec to read that exported file.

const fs = require('uxp').storage.localFileSystem;

async function quickExport(destFolder, layerOnly = false) {
   try {
      const result = await batchPlay([
         {
            "_obj": layerOnly ? "exportSelectionAsFileTypePressed" : "exportDocumentAsFileTypePressed",
            "_target": { "_ref": "layer", "_enum": "ordinal", "_value": "targetEnum" },
            "fileType": "jpg",
            "quality": 100,
            "metadata": 0,
            destFolder,
            "sRGB": true,
            "openWindow": false,
            "_options": { "dialogOptions": "dontDisplay" },
         },
      ], {})
   }
   catch (error) {
     await writeLog("Error in quickExport " + error); }
   }
}

var tempFolder = await fs.getTemporaryFolder();
await quickExport(tempFolder.nativePath);

setTimeout(async () => {
      const entries = await tempFolder.getEntries();
      var jpgFile = entries.filter(entry => {
         if (entry.name == "SampleDoc.jpg" && entry.isFile) {
             return true;
         }
      });
}, 2000);
1 Like