Page 1 of 1
[Solved] : User scripts steal focus
Posted: 16 Oct 2018 14:28
by Sander Bouwhuis
I have user scripts that execute applications on all selected items.
I get this popup window:
Code: Select all
Please wait...
The shelled process has not yet finished.
Click cancel to stop waiting.
Unfortunately, this CONSTANTLY steals the focus! Trying to do other things while a very long process is executing is almost impossible when you can't type because every couple of seconds the focus goes to that Xyplorer window.
It makes doing any work impossible. I literally have to walk away from the computer to go to the toilet or get coffee or something when I execute scripts.
Please fix!!!
Re: [v19.20] : User scripts steal focus
Posted: 16 Oct 2018 14:35
by highend
As long as any window belonging to such an application will need to be shown (by the started application), it's totally normal that this happens. The OS shifts the focus in that case.
Redesigning your scripts could help...
Re: [v19.20] : User scripts steal focus
Posted: 16 Oct 2018 16:44
by Sander Bouwhuis
This is my script:
Code: Select all
foreach($dir, "<get SelectedItemsNames |>")
{
$path = get("path");
if(exists("$path\$dir") == 2)
{
run """C:\Utilities\7-Zip\7z.exe"" a -r -mx0 ""$dir.7z"" "".\$dir\*""", , 1, 2;
}
}
What should I change to prevent Xyplorer from stealing the focus? I don't need to see the minimized commandline window that is in the background, if that helps. But, I would like to be able to cancel the process if at all possible.
PS
I didn't write this script. Someone on this forum kindly created it for me.
Re: [v19.20] : User scripts steal focus
Posted: 16 Oct 2018 17:19
by highend
You could have the script create a .bat file that executes all packing jobs and hand over the focus only once when the .bat is executed afterwards but ofc this doesn't work when you want to be able to abort single jobs. Either live with it or write a wrapper that you call instead which hands over the focus back to XY once it was invoked
Re: [v19.20] : User scripts steal focus
Posted: 17 Oct 2018 08:08
by Sander Bouwhuis
Ok, just to get this straight:
1. Redirect the 7z commands to a .bat file
2. Execute the batch file as the only file
That is fine with me. I don't need to stop individual tasks.
How would I redirect the commands to a single batch file?
Code: Select all
foreach($dir, "<get SelectedItemsNames |>")
{
$path = get("path");
if(exists("$path\$dir") == 2)
{
run ""echo "C:\Utilities\7-Zip\7z.exe"" a -r -mx0 ""$dir.7z"" "".\$dir\*" > 7zBatchTemp.bat"", , 1, 2;
}
}
run ""7zBatchTemp.bat"", , 1, 2;
run ""del "7zBatchTemp.bat"", , 1, 2;
Is it something like that?
Re: [v19.20] : User scripts steal focus
Posted: 17 Oct 2018 10:13
by highend
Code: Select all
$tmpFile = "%TEMP%\7zBatchTemp.bat";
$content = "";
foreach($dir, "<get SelectedItemsNames |>")
{
$path = get("path");
if(exists("$path\$dir") == 2)
{
$command = <<<>>>
START "" /B /WAIT "C:\Utilities\7-Zip\7z.exe" a -r -mx0 "$path\$dir.7z" "$path\$dir\*"
>>>;
$content .= $command . <crlf>;
}
}
setting "BackgroundFileOps", 0;
writefile($tmpFile, $content, , "utf8");
run $tmpFile, , 1, 2;
delete 0, 0, $tmpFile;
Re: [v19.20] : User scripts steal focus
Posted: 17 Oct 2018 13:06
by Sander Bouwhuis
Wow! You completely changed the script.
It seems to work great though, so I'm super happy!!!
One small thing... can the name of the batch file be made random? If I want to run 2 scripts at the same time I can't have the batch file be called the same thing.
Re: [v19.20] : User scripts steal focus
Posted: 17 Oct 2018 13:33
by highend
Then replace this:
Code: Select all
$tmpFile = "%TEMP%\7zBatchTemp.bat";
with this:
Code: Select all
$tmpFile = "%TEMP%\7zBatchTemp_" . CreateRandomName() . ".bat";
and put the function at the end of the script (NOT indented):
Code: Select all
function CreateRandomName($numChars=8, $upperAndLower=true, $chars="") {
if (!regexmatches($numChars, "^\d+$") || $numChars <= 0) { $numChars = 8; }
if ($chars == "") { $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; }
$name = "";
while ($i++ < $numChars) {
$char = gettoken($chars, rand(1, strlen($chars)), "");
if ($upperAndLower && rand(0, 1)) { $char = recase($char, "u"); }
$name .= $char;
}
return $name;
}
Re: [v19.20] : User scripts steal focus
Posted: 17 Oct 2018 17:01
by Sander Bouwhuis