GithubHelp home page GithubHelp logo

00mjk / mac-window-select Goto Github PK

View Code? Open in Web Editor NEW

This project forked from karaggeorge/mac-window-select

0.0 0.0 0.0 10.85 MB

Prompt the user to select a window on macOS, mimicking the native screenshot utility

Swift 87.91% JavaScript 12.09%

mac-window-select's Introduction

mac-window-select

Prompt the user to select a window on macOS, mimicking the native screenshot utility

Requires macOS 10.12 or later. macOS 10.13 or earlier needs to download the Swift runtime support libraries.

Install

$ npm install mac-window-select

Usage

const selectWindow = require('mac-window-select');

selectWindow({appsToIgnore: ['iTerm2']}).then(console.log);

// {
//   canceled: false,
//   window: {
//     ownerName: 'Google Chrome',
//     name: 'karaggeorge/mac-window-select: Select a window on macOS, mimicking the native screenshot utility',
//     y: 23,
//     x: 1920,
//     width: 1920,
//     height: 1057,
//     number: 141349,
//     pid: 69132
//   }
// }

const process = selectWindow().then(console.log);

process.cancel();

// {
//   canceled: true,
//   window: undefined
// }

Demo

API

selectWindow(options?: {appsToIgnore: string[]}): PCancelable<Object>

Trigger the UI to prompt the user to select a window.

Returns PCancelable<Object> - Object contains the following:

  • canceled Boolean - whether or not the process was canceled, either by the user or by calling .cancel()
  • window Object - window that was selected. Will be undefined if the process is canceled or if the module is not supported

The returned promise is an instance of PCancelable, so it has a .cancel() method which can be used to kill the process

options.appsToIgnore

Array of app names to ignore. If an app is in this list, it will be ignored and the app below it will be used instead.

Note: Use this if you want your own app to not be selectable

selectWindow.isSupported

Will be true if the module is supported (based on macOS version).

Limitations

Currently, there's no way to track the keyboard events, since the script never steals focus from the previously focused app. If you want Escape to cancel, you have to track it in your app and call the cancel() method on the returned promise.

Related

  • mac-focus-window - Focus a window and bring it to the front on macOS
  • mac-windows - Provide Information about Application Windows running

License

MIT

mac-window-select's People

Contributors

karaggeorge avatar sindresorhus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.