How to script a non-modal msg to the user?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: How to script a non-modal msg to the user?

Post by klownboy »

Big +1 for this wish!

Another "very impressive" to you highend. I like the fact that it stays on top. I'll be able to make use of this in some existing scripts where currently a different technique is used.

Would there be any way to combine your stay-on-top VB script message with another VB script that provided a timed message (see below). The script was originally provided by Stefan here http://www.xyplorer.com/xyfc/viewtopic. ... age#p71980 So the message would stay on top but it would self destruct after a designated period. I'm thinking that if the user didn't respond (as in this example select the files required) within say 5 or 6 seconds the script would simple end, or possibly reload, or provide another message to say aborting or similar. If he selects the files and hits OK as he should, the script proceeds as normal.

Code: Select all

  global $t_msg;
  if (Get('CountSelected') < 2) {
    $t_msg = "Make sure that all the files and folders that you want to process are selected in the list. Click OK when your selection is complete.";
    Sub "_TIMED_MESSAGE";
  }
    Text Get('SelectedItemsPathNames'), /*width*/, /*height*/, 'You selected the following items:';
    end 1;
"_TIMED_MESSAGE";
  global $t_msg;		  
  $waitSec = 6;
  $out="";
  foreach($line, $t_msg, "<crlf>"){ $out = $out . chr(34) . $line . chr(34) . " & vbCRLF _<crlf> & ";}
  $out = replace($out, "&", "", ,strlen($out) -3, 1);

  //Create the VBS file:
  $VBS = <<<HEREDOC
text =  $out 
SET WS = CreateObject("WScript.Shell")
'//WshShell.Popup   strMessage [,intSecondsToWait] [,strTitle] [,intType]
WS.popup text, $waitSec
HEREDOC;
  writefile("<xyscripts>\tempVBS.vbs", $VBS);
  run ("wscript ""<xyscripts>\tempVBS.vbs"""), ,2,0;
Thanks,
Ken

Edit: See example below with a timed message which stays-on-top.
Last edited by klownboy on 26 Sep 2014 01:31, edited 1 time in total.

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

Re: How to script a non-modal msg to the user?

Post by highend »

Easy...

Just replace:

Code: Select all

WS.popup text, $waitSec
with

Code: Select all

WS.popup text, $waitSec, , vbInformation+vbSystemModal
The title of that window must be put into the ", ," part (if necessary)
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4462
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: How to script a non-modal msg to the user?

Post by klownboy »

highend wrote:Easy...
:) Easy for you. I figured you'd use the same code as you did in your example, but where, that was the hard part

Anyway it worked great. This actually has a good practical use (see below). In this particular example, if after the message displays, I select the files and don't do anything the message goes away and the script would continue (i.e., without even hitting the OK button in the message box to proceed). If I pre-select the files, obviously no message at all. If no files are selected by the end of the timed message, the script would be reloaded and the message re-appears. Of course you could do whatever the script needed.

Code: Select all

  global $t_msg;
  if (Get('CountSelected') < 2) {
    $t_msg = "Make sure that all the files and folders that you want to process are selected in the list. Click OK when your selection is complete.";
    Sub "_TIMED_MESSAGE";
  }
  if (Get('CountSelected') >= 2) {
    Text Get('SelectedItemsPathNames'), /*width*/, /*height*/, 'You selected the following items:';
    end 1;   // or more commands
	} else {
	load(self("file"));}
"_TIMED_MESSAGE";
  global $t_msg;		  
  $waitSec = 6;
  $out="";
  foreach($line, $t_msg, "<crlf>"){ $out = $out . chr(34) . $line . chr(34) . " & vbCRLF _<crlf> & ";}
  $out = replace($out, "&", "", ,strlen($out) -3, 1);
 //Create the VBS file:
  $VBS = <<<HEREDOC
text =  $out 
SET WS = CreateObject("WScript.Shell")
'//WshShell.Popup   strMessage [,intSecondsToWait] [,strTitle] [,intType]
WS.popup text, $waitSec, , vbInformation+vbSystemModal
HEREDOC;
  writefile("<xyscripts>\tempVBS.vbs", $VBS);
  run ("wscript ""<xyscripts>\tempVBS.vbs"""), ,2,0;
Thanks again,
Ken

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: How to script a non-modal msg to the user?

Post by nerdweed »

A simple oneliner
run ('CMD /C "ECHO Message To Alert You && PAUSE"') ;

Post Reply