I’ve tryed yor code. The toolkit has created a new source file and opened it with this content:
theFile.remove();
theFolder.remove();
So, it throws an error, because in the new file theFile is not defined. What you can do is add an include statment, referencing your script, but you must call app.scheduleTask from other file, because if you call it in the same script, the function will run and run until you close after effects. Other problem is that your variables are inside of a function so they are not accesible from outside. You can solve it by some ways, this is my aproach:
//Script 1:
{
var TempFile = new Object();
TempFile.folderPath = "~/Desktop/tempFldr2";
TempFile.theFolder = new Folder (TempFile.folderPath.toString());
TempFile.scriptPath = (new File($.fileName)).toString();
TempFile.str = "TempFile.theFolder.remove();"
TempFile.theFolder.create()
}
//Script 2:
{
#include "Script1.jsx"
app.scheduleTask(TempFile.str,1000, false);
}