Skip to content
Get metadata about the active window (title, id, bounds, owner, etc)
Branch: master
Clone or download
Latest commit 8effb6e Jun 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create funding.yml May 28, 2019
Sources/active-win Return `undefined` if there is no active window Mar 25, 2019
lib Fix Linux window name logic for xterm (#50) Jun 23, 2019
.editorconfig Meta tweaks Dec 23, 2017
.gitattributes
.gitignore Rewrite the macOS implementation in Swift Jan 1, 2018
.npmrc Meta tweaks Dec 23, 2017
.travis.yml Require Node.js 8 Oct 17, 2018
Package.swift Require Node.js 8 Oct 17, 2018
index.d.ts Add `memoryUsage` for Windows and `owner.path` and `memoryUsage` for … May 20, 2019
index.js Require Node.js 8 Oct 17, 2018
index.test-d.ts Add `memoryUsage` for Windows and `owner.path` and `memoryUsage` for … May 20, 2019
license Meta tweaks Dec 23, 2017
package.json 5.1.1 Jun 23, 2019
readme.md Add `memoryUsage` for Windows and `owner.path` and `memoryUsage` for … May 20, 2019
test.js Require Node.js 8 Oct 17, 2018

readme.md

active-win Build Status

Get metadata about the active window (title, id, bounds, owner, etc)

Works on macOS, Linux, Windows.

Install

$ npm install active-win

Usage

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

(async () => {
	console.log(await activeWin());
	/*
	{
		title: 'Unicorns - Google Search',
		id: 5762,
		bounds: {
			x: 0,
			y: 0,
			height: 900,
			width: 1440
		},
		owner: {
			name: 'Google Chrome',
			processId: 310,
			bundleId: 'com.google.Chrome',
			path: '/Applications/Google Chrome.app'
		},
		memoryUsage: 11015432
	}
	*/
})();

API

activeWin()

Returns a Promise<Object> with the result, or Promise<undefined> if there is no active window or if the information is not available.

activeWin.sync()

Returns an Object with the result, or undefined if there is no active window.

Result

  • platform (string) - 'macos' | 'linux' | 'windows'
  • title (string) - Window title
  • id (number) - Window identifier
  • bounds (Object) - Window position and size
    • x (number)
    • y (number)
    • width (number)
    • height (number)
  • owner (Object) - App that owns the window
    • name (string) - Name of the app
    • processId (number) - Process identifier
    • bundleId (string) - Bundle identifier (macOS only)
    • path (string) - Path to the app
  • memoryUsage (number) - Memory usage by the window owner process

OS support

It works on macOS, Linux, and Windows 7+.

Note: On Windows, there isn't a clear notion of a "Window ID". Instead it returns the memory address of the window "handle" in the id property. That "handle" is unique per window, so it can be used to identify them. Read more….

Related

Maintainers

License

MIT

You can’t perform that action at this time.