Need to delay for 10sec to call a function

I have a button works fine no problem.

function OnClick(clickData)

if (clickData.func.sourcetab.selected.count !== 0)
	var eSel = new Enumerator(clickData.func.sourcetab.selected);
	var getfoldername = eSel.item().realpath.filepart;
	var re = /\s\([0-9]+?\)\.(.*)/;
	var regfolder = getfoldername.replace(re, "");

	var AlbumCover = regfolder.match(/^[^.]+/);
	var AlbumFolderwithCover = AlbumCover[0] + ' Covers';

var cmd = clickData.func.command;
cmd.RunCommand('Copy HERE CREATEFOLDER="' + regfolder + '/' + AlbumFolderwithCover + '"');
cmd.RunCommand('GO "' + regfolder + '"');


	var FirstFile = clickData.func.sourcetab.selected_files(0);
cmd.RunCommand('Copy HERE  AS coverart.jpg CREATEFOLDER="' + regfolder + '"');
cmd.RunCommand('Copy HERE  AS folder.jpg CREATEFOLDER="' + regfolder + '"');
cmd.RunCommand('Copy HERE AS FolderIcon.jpg CREATEFOLDER="' + regfolder + '"');

cmd.RunCommand('Select (coverart|folder|FolderIcon).jpg'); 
cmd.RunCommand('Set FOCUS=Toggle');
cmd.RunCommand("Set VIEW=Thumbnails");


cmd.RunCommand("%ProgramFiles(x86)%\\ObviousIdea\\Light Image Resizer 6\\Resize.exe {allfilepath$} /profile=\"Coverart\" /run");

cmd.RunCommand("%ProgramFiles(x86)%\\ObviousIdea\\Light Image Resizer 6\\Resize.exe {allfilepath$} /profile=\"FolderIcon\" /run");
cmd.RunCommand('Select FolderIcon.ico');

			var dlg = clickData.func.Dlg;
			dlg.buttons = "OK";
			dlg.message ="আপনি কোন সিডির কভার ফটো সিলেক্ট করেননি\n দয়া করে আগে সিডির কভার ফটো সিলেক্ট করুন।"
			dlg.title = "Error!© Md. Khalid Hossain 2021";
			dlg.want_resize = true;;


Now I want to marge a function with that, This function also works fine in single button.

function OnClick(clickData)
	if (clickData.func.sourceTab.selected_files.count != 1) {

	var selFileName = clickData.func.sourceTab.selected_files(0).name ;

	var fso = new ActiveXObject("Scripting.FileSystemObject");
	var iniPath = fso.BuildPath(clickData.func.sourceTab.path, "desktop.ini");

	if (fso.FileExists(iniPath)){
	    var txtFileMeta = fso.GetFile(iniPath);
		txtFileMeta.Attributes = 0; // Clear Read-Only + Hidden.

	var txtFile = fso.CreateTextFile(iniPath, true);
	txtFile.WriteLine("IconResource=" + selFileName + ",0");

    var txtFileMeta = fso.GetFile(iniPath);
	txtFileMeta.Attributes = 3; // Read-Only + Hidden.

	var currentPath =  fso.GetFolder(clickData.func.sourceTab.path);
	currentPath.Attributes = 1; // Read-Only.

	var icoFileName = clickData.func.sourceTab.selected_files(0);  
  	var fso = new ActiveXObject("Scripting.FileSystemObject");
  	var icoFileMeta = fso.GetFile(icoFileName);
  	icoFileMeta.Attributes =  3; //  Hidden.

The problem is that the 2nd function Need a .ico file for perform. I had convert a Image file into .ico file in my 1st button with this line

cmd.RunCommand("%ProgramFiles(x86)%\\ObviousIdea\\Light Image Resizer 6\\Resize.exe {allfilepath$} /profile=\"FolderIcon\" /run");

This Line have Run a 3rd party program name Light Image Resizer 6 and convert a Image file into .ico file, and for Run the 3rd party program and converting It's take some seconds. So I need to delay the 2nd button Code for 10sec, How to make the delay? Now the 2nd button code has been run before the Image file had been finished the converting.

Delays for the specified number of milliseconds before returning.

Delay doesn't workout here, any other idea to marge the buttons?

DOpus.Delay does work but what you need is not Delay, because cmd.RunCommand runs your command asynchronously. Delay with fixed amounts is very bad design anyway, because you'll either wait too long or too short. What you rather need is running your external command synchronously, e.g.

var shell = new ActiveXObject('');
// look up WScript shell run examples on the net
// it's not a DOpus topic
// last param true=wait does the trick
shell.Run("your_cmd_here", 0, true); // 0: hidden, true: wait
// at this point your external program has finished, your script can continue
1 Like

As an aside: cmd.RunCommand itself is synchronous, but the command it is actually running may not be. You can sometimes use @sync to change that, but it can also depend on the command or program being run (which may simply hand off the request to another process and then exit).