[Solved] : User scripts steal focus

Things you’d like to miss in the future...
Post Reply
iycgtptyarvg
Posts: 222
Joined: 10 Jun 2008 15:40
Location: Netherlands

[Solved] : User scripts steal focus

Post by iycgtptyarvg »

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!!!
Last edited by iycgtptyarvg on 17 Oct 2018 17:01, edited 1 time in total.
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [v19.20] : User scripts steal focus

Post 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...
One of my scripts helped you out? Please donate via Paypal

iycgtptyarvg
Posts: 222
Joined: 10 Jun 2008 15:40
Location: Netherlands

Re: [v19.20] : User scripts steal focus

Post by iycgtptyarvg »

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.
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [v19.20] : User scripts steal focus

Post 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
One of my scripts helped you out? Please donate via Paypal

iycgtptyarvg
Posts: 222
Joined: 10 Jun 2008 15:40
Location: Netherlands

Re: [v19.20] : User scripts steal focus

Post by iycgtptyarvg »

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?
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [v19.20] : User scripts steal focus

Post 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;
One of my scripts helped you out? Please donate via Paypal

iycgtptyarvg
Posts: 222
Joined: 10 Jun 2008 15:40
Location: Netherlands

Re: [v19.20] : User scripts steal focus

Post by iycgtptyarvg »

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.
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [v19.20] : User scripts steal focus

Post 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;
}
One of my scripts helped you out? Please donate via Paypal

iycgtptyarvg
Posts: 222
Joined: 10 Jun 2008 15:40
Location: Netherlands

Re: [v19.20] : User scripts steal focus

Post by iycgtptyarvg »

Sir, tell me honestly... are you a wizard?

:appl: :appl: :appl:
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.

Post Reply