Start .vbs script without icon of wscript.exe in the taskbar - wsh

How can I Start .vbs script without icon of wscript.exe in windows taskbar

Unlike the CScript.exe, Windows does not show the WScript.exe host executable icon by default (shows Popup, MsgBox, InputBox and Echo only). Check the difference:
start "" cscript 30598853.vbs
will show a Windows script host icon in the Windows taskbar whilst
start "" wscript 30598853.vbs
will not. In both cases, an additional Windows script host icon will appear for a while (i.e. for the duration of the Popup is active in given example)...
Create a sample 30598853.vbs script as follows:
Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
BtnCode = WshShell.Popup( _
WScript.ScriptName & vbNewLine & "Exit script?" _
, 5 _
, WScript.FullName _
, vbOKCancel + vbQuestion)
If BtnCode = vbOK Then Exit Do
Wscript.Sleep 15000
Loop
Edit
To the best of my belief, a window invoked via Popup method or MsgBox function or InputBox function (and Echo method in case of the WScript.exe host executable as well) will always show it's icon in the taskbar. This happens regardless of that particular window is on top or isn't.
Read in another forum that one could assign a fully transparent icon to a particular executable...

Related

What would the equivalent code be in JXA for getting the URL from a Firefox browser?

tell application "System Events" to get value of UI element 1 of combo box 1 of toolbar "Navigation" of first group of front window of application process "Firefox"
I am using the above in an AppleScript to get the URL from the Firefox browser, what would the equivalent be using JXA.
I am using JXA rather than an AppleScript because applescripts hate when you don't have a specific browser installed but still use it in the script.
Here I tested the apple-script you mentioned from the GitHub site that you would like to translate into JXA.
It contains 2 important bugs: 1) When the script is run, the front application is one, which executes the script and not the browser. This has been erroneously ignored. 2) If you do not have the Google Chrome application installed, then the script will not even compile.
The following Apple-script fixes these 2 critical bugs. I am not a JXA expert, so I leave my script as is.
property chromium_variants : {"Google Chrome", "Chromium", "Opera", "Vivaldi", "Brave Browser", "Microsoft Edge"}
property webkit_variants : {"Safari", "Webkit"}
property browsersList : chromium_variants & webkit_variants & "firefox"
tell application "System Events"
repeat 10 times
set frontApp to name of first process whose frontmost is true
if browsersList contains frontApp then exit repeat
set visible of process frontApp to false
end repeat
end tell
if (frontApp starts with "Safari") or (frontApp starts with "Webkit") then
set videoURL to run script "tell application " & frontApp & " to return URL of front document"
set videoTitle to run script "tell application " & frontApp & " to return name of front document"
else if frontApp is "Firefox" then
set videoURL to my firefoxCurrentTabURL()
set videoTitle to my firefoxCurrentTabUTitle()
else if (frontApp starts with "Google Chrome") or (frontApp starts with "Chromium") or (frontApp starts with "Opera") or (frontApp starts with "Vivaldi") or (frontApp starts with "Brave Browser") or (frontApp starts with "Microsoft Edge") then
set videoURL to run script "tell application " & frontApp & " to return URL of active tab of first window"
set videoTitle to run script "tell application " & frontApp & " to return title of active tab of first window"
else
return "You need a supported browser as your frontmost app"
end if
return {videoURL:videoURL, videoTitle:videoTitle}
on firefoxCurrentTabURL()
-- Store the current clipboard contents.
set theClipboard to (the clipboard as record)
-- Set the clipboard to a default blank value
set the clipboard to ""
-- Bring Firefox to the front, highlight the URL in the URL field and copy it.
tell application "System Events"
set frontmost of application process "firefox" to true
keystroke "lc" using {command down}
end tell
-- Read the clipboard contents until either they change from "" or a second elapses.
repeat 10 times
delay 0.2
set theURL to the clipboard
if theURL is not "" then exit repeat
end repeat
-- Restore the old clipboard contents.
set the clipboard to theClipboard
return theURL
end firefoxCurrentTabURL
on firefoxCurrentTabUTitle()
tell application "System Events" to tell process "firefox"
set frontmost to true
set the_title to name of windows's item 1
set the_title to (do shell script "echo " & quoted form of the_title & " | tr '[' ' '")
set the_title to (do shell script "echo " & quoted form of the_title & " | tr ']' ' '")
end tell
end firefoxCurrentTabUTitle

Command line print via GhostScript is handling printer settings differently if using print dialog

I'm trying to print a PDF file via GhostScript command and want
to keep alive the default printer settings be done within the system environment (Windows 10 - set paper tray 3 as default).
When is done so without silent mode by using the upcoming printer dialog this works fine (even without setting up paper tray especially)
BUT - as I want the process to be done without dialog - I've also tried it with defining the printer name within the command line.
What works properly, is that the print out happens without dialog - BUT the default configured paper tray doesn't get used - when I print silently - paper tray 1 is used
Is there a possibility to keep the default paper tray settings alive while naming the printer within the command line?
Here is my codeline:
gswin64c.exe -dPrinted -dNoCancel -dBATCH -dNOPAUSE -dNOSAFER -q -dBitsPerPixel=4 -sDEVICE=mswinpr2 -sPAPERSIZE=a4 -sOutputFile=%printer%" + "\"" + printerName + "\"" +" " + "\""+pdfFileName+ "\"";
To the best of my knowledge, the mswinpr2 device always uses the default setup of the printer, unless you get a print dialog, in which case you can override the default.
Perhaps the default tray isn't the one you think it is.
Yes - I'm sure that the paper tray is set correct (tray3)
It is used when printing with other applications and also when I print via Ghostscript using a print dialog but not when I send a print job silently via command line.
Oliwan

how to run .fsx in fsi

Exploring F# with FSharp.Charting I thought I would start with a simple 'hello world' but it leaves me with more questions then lines of code.
#load #"..\packages\FSharp.Charting.0.90.14\FSharp.Charting.fsx"
open FSharp.Charting
let chart = Chart.Line([ for x in 0 .. 10 -> x, x*x ])
chart.ShowChart()
chart.SaveChartAs(#"C:\Temp\chart.png",ChartTypes.ChartImageFormat.Png)
This works in interactive window in VS, but what I want to do is execute this script from the cmd line (using fsi.exe). I made an association with fsx files to fsi, but when I execute it it opens fsi but no chart is created. What do I need to do?
Short answer: add the following line at the end of your program:
System.Windows.Forms.Application.Run()
Long answer:
The chart does get created, but it immediately disappears, because your program immediately exits, right after creating the chart. This does not happen in the F# Interactive window in Visual Studio, because the F# interactive window doesn't close immediately after executing your program - it just hangs out there, waiting for you to submit more code for execution.
In order to make your program not exit immediately, you could implement some waiting mechanism, such as waiting for a set amount of time (see System.Threading.Thread.Sleep) or waiting for the user to press Enter (via stdin.ReadLine()), etc.
However, this won't actually help you, because there is the next problem: the chart is drawn via Windows Forms, which relies on the message loop running - otherwise the window can't receive messages, and so can't event paint itself.
FSI does have its own built-in event loop, and this is how your program works under VS. However, if you implement a "waiting" mechanism (e.g. stdin.ReadLine()), this event loop will be blocked - won't be able to pump messages. Therefore, the only sane way to keep your program from exiting, while not interfering with the functioning of the chart window, is to start your own event loop. And this is exactly what Application.Run() does.
Saving to disk without displaying:
(in response to comment)
From what I understand, the FSharp.Charting library was intended as a quick-and-dirty way to display charts on the screen, primary use case being exploring datasets live within F# Interactive. More specifically, some key properties of the Chart object, such as ChartAreas and Series are not initialized upon chart creation, but only when it is shown on the screen (see source code), and without these properties the chart remains empty.
Short of submitting a pull request to the library, I recommend dropping down to the underlying System.Windows.Forms.DataVisualization.Charting.Chart:
open System.Windows.Forms.DataVisualization.Charting
let ch = new Chart()
ch.ChartAreas.Add( new ChartArea() )
let s = new Series( ChartType = SeriesChartType.Line )
s.Points.DataBind( [for x in 1..10 -> x, x*x], "Item1", "Item2", "" )
ch.Series.Add s;
ch.SaveImage(#"C:\Temp\chart.png", System.Drawing.Imaging.ImageFormat.Png)

What's the number passed when Windows opens a screensaver's settings?

I'm writing a screensaver, and checked for the parameter /c to see if the screensaver has to be started, or the settings windows should be shown.
I found that the actual parameter passed is /c followed by a number, i.c. 3805726, the full argument is
/c:3805726
What does this number mean?
If the /c parameter does not specify a number, the screensaver is expected to display its configuration dialog modal to the HWND returned by GetForegroundWindow() (the "Screen Saver Settings" window).
If the /c parameter specifies a number (either in /c:### or /c ### format), the number represents an HWND (similar to the /p parameter) that the screensaver is expected to display its configuration dialog modal to. On my Win7 machine, that HWND contains the contents of the "Screen Saver" tab on the "Screen Saver Settings" window.

Responsive Compile-and-Run Vim Mapping

I have the following mapping in my .vimrc.
:nmap <F5> :<C-U>make %:r && ./%:r<CR>
I press F5 in VIM, and it compiles, exits VIM, and runs my code. When the program terminates, it asks me to "press ENTER or enter a command to continue." It then takes me to a blank screen with the text (1 of 5): and the same "press ENTER or enter a command to continue" prompt. I press enter and it finally returns me back to VIM. This behavior is consistent across the board. Is there a way to remove any or both of those occurrences? Perhaps have the mapping press ENTER twice after the program terminates? If so, how?
EDIT: So I realized appending two more <CR>'s doesn't quite solve the problem. As soon as the program terminates, it IMMEDIATELY goes back to VIM and I don't have time to review the output. Can I make the mapping wait for ME to press the first enter, and automatically press the 2nd ENTER afterwards?
Would this work:
nmap <F5> :<C-U>silent make %:r<CR>:redraw!<CR>:!./%:r<CR>
A longer solution but this one also allows you to see errors (reference):
:function! MakeAndRun()
: silent make %:r
: redraw!
: if len(getqflist()) == 1
: !./%:r
: else
: for i in getqflist()
: if i['valid']
: cwin
: winc p
: return
: endif
: endfor
: endif
:endfunction
:nmap <F5> :call MakeAndRun()<cr>
Yes and yes (you answered your own question):
:nmap <F5> :<C-U>make %:r && ./%:r<CR><CR>
For me this works fine:
" Compile
noremap <F4> :<C-U>silent make<CR>:redraw!<CR>
" Automatically open, but do not go to (if there are errors) the quickfix /
" location list window, or close it when is has become empty.
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
It compiles, and immediately jumps to vim, showing the quickfix window. No intermediate enters.

Resources