1.0.4 • Published 6 years ago

window-info v1.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

window-info

npm version

window-info is a readable stream that pushes data about windows on screen on MacOS.

It opens a Python process which uses Quartz library to get information about windows.

yarn add -E window-info

Table of Contents

API

The default exported class is WindowInfo which is a Readable stream.

import WindowInfo from 'window-info'

WindowInfo Stream

WindowInfo is a Readable stream open in object mode with high watermark set to 0 to prevent caching of window data when receiving streams haven't processed previous data. This ensures that the newer data is always as fresh as possible. The presence of the delay value ensures that no data is written before the delay has passed since last write.

constructor(  delay?: number = 1000,): WindowInfo

Create a new stream. The delay argument controls how often to query data.

import { Transform } from 'stream'
import WindowInfo from 'window-info'

(async () => {
  const wi = new WindowInfo({
    delay: 1000,
  })
  let receivedData = 0
  const limit = 1
  wi
    .pipe(new Transform({
      transform(data, enc, next) {
        if (receivedData < limit) {
          this.push(data)
        } else {
          // limit reached
          wi.destroy()
        }
        receivedData++
        next()
      },
      objectMode: true,
      highWaterMark: 0, // disable receiving buffering
    }))
    .pipe(new Transform({
      transform(data, enc, next) {
        this.push(JSON.stringify([
          ['winid', 'App Name', 'Window Title', 'pid'],
          ...data,
        ]))
        next()
      },
      writableObjectMode: true,
    }))
    .pipe(process.stdout)
})()
winidApp NameWindow Titlepid
33SystemUIServerAppleClockExtra386
73AviraItem-0501
60PostgresMenuHelperItem-0525
51Little Snitch AgentItem-0348
20SystemUIServerAppleBluetoothExtra386
24SystemUIServerAirPortExtra386
29SystemUIServerAppleTextInputExtra386
37SystemUIServerAppleUser386
45SpotlightItem-0405
18SystemUIServerSiri386
16SystemUIServerNotificationCenter386
3Window ServerMenubar177
4292Visual Studio Code2-fork.md — window-info367
4291Visual Studio Codepackage.json — documentary367
4171Google Chromeartdecocode/window-info: Window Info is a readable stream that pushes data about windows on screen on MacOS.51791
59iTunesiTunes382
4Window ServerBackstop Menubar177
49Finder387
41DockDesktop Picture - Sierra 2.jpg384
2Window ServerDesktop177

destroy(): void

Call the destroy method to kill the underlying python process and end the stream.

Data Type

Each data row in the read chunk contains information about open windows in form of an array.

For example, WindowInfo can generate the following:

[
  [480, "Code", "example.js — window-info", 405],
  [89, "Google Chrome", "Stream | Node.js v10.2.1 Documentation", 410]
]

The type definition then is according to the position in the array.


(c) Art Deco 2018