Intro guide: node.js and active-win for window info

At some point I hope to be able to make use of the information provided by active-win, a Node.js package.
(There is a potentially easier-to-use package, active-win-cli, but I can’t get it to install yet.)

As you’ll see, you can grab:

  • Platform name;
  • Window title;
  • Id (aka the Windows handle or hwnd);
  • Process info (name, process ID, path, and screen bounds).

Pictures being worth a thousand words, here goes.
Code screenshot:

Probably too small to read - here’s the code:

# Here we use node.js
# and active-win (
# The goal is grab useful information from the currently active window
# for further processing.
System.GetEnvironmentVariable Name:  'USERNAME' Value=> UserName
# Start with a browser.
WebAutomation.LaunchChrome \
            Url:  "https:\\" \
            WindowState:WebAutomation.BrowserWindowState.Normal \
            ClearCache:False \
            ClearCookies:False \
            BrowserInstance=> Browser
wait 3
# Now we get the window details, written to StandardOutput
System.RunDOSCommand \
            DOSCommandOrApplication: "node awin1.js" \
            WorkingDirectory:'C:\Users\\' + UserName + '\Documents\Robin\9.2\awin' \
            StandardOutput=> BrowserOutput \
            StandardError=> StandardError \
            ExitCode=> ExitCode
# Log the output.
Console.Write Message: BrowserOutput
# Close the browser and go on to Excel
WebAutomation.CloseWebBrowser BrowserInstance: Browser
# Open a test file
Excel.LaunchAndOpen \
            Path: 'C:\Users\\' + UserName + '\Documents\Robin\9.2\awin\robintest.xlsx' \
            Visible:True \
            Password:'' ReadOnly:False \
            LoadAddInsAndMacros:False \
            Instance=> ExcelInstance
# Grab details of this window
System.RunDOSCommand \
            DOSCommandOrApplication: "node awin1.js" \
            WorkingDirectory:'C:\Users\\' + UserName + '\Documents\Robin\9.2\awin' \
            StandardOutput=> ExcelOutput \
            StandardError=> StandardError \
            ExitCode=> ExitCode
wait 3
# Close Excel
Excel.Close Instance: ExcelInstance
# Finally, display the details
Display.ShowMessage \
            Title:'Excel information from active-win' \
            Message: ExcelOutput \
            Icon:Display.Icon.None \
            Buttons:Display.Buttons.OK \
            DefaultButton:Display.DefaultButton.Button1 \
            IsTopMost:False \
            ButtonPressed=> ButtonPressed

Console output from ‘active-win’:


A message box of the output for Excel:


And finally the code listing for ‘awin1.js’:

const activeWin = require('active-win');

(async () => {
	console.log(await activeWin());

Best regards,


Very nice guide @burque505!
Keep 'em coming!

Best regards,