Search code examples
javascriptwaitextendscript

How do I Wait With Extends Script (Adobe)


i'm currently working on an extends script which is the technology that we can use to create extension for adobe softwares, its a javascript similar script language Im working on a script to automate some boring and repetitive tasks

Here is my problem i've to wait the creation of a bin before use a variable which call this bin but i can't, i tried

.then( Promise => { //Some Code }) ; setTimeout(Function(), time); nothing is working

Can someone help me please ? Here is my code

    root = app.project.rootItem
    newFilesPath = "Path"
    newFilesBin = root.children[0]
    
    app.project.importFiles(newFilesPath, true, newFilesBin, false)
    
    app.project.save()
    
    for(i=0; i<newFilesBin.children.numItems; i++){  //here is the problem it tells me that
        newFile = newFilesBin.children[i]            //newFilesBin is null, i think he has not the 
                                                     //time to create the file and then to put it 
                                                     //in the variable
        name = newFile.name
    
        newTiktokBin = root.createBin(name)
    
        root.children[i].children[0].moveBin(newTiktokBin)
    }


Solution

  • You can simply send your program to sleep for any amount of milliseconds by using the $.sleep() method.

    $.sleep(1000);  // sends the program to sleep for a second
    

    There is no such thing as .then() or promises in ExtendScript, as it is basically an ancient version of JavaScript.