MCPcopy Index your code
hub / github.com/nut-tree/nut.js

github.com/nut-tree/nut.js @v4.2.0 sqlite

repository ↗ · DeepWiki ↗ · release v4.2.0 ↗
459 symbols 1,174 edges 140 files 95 documented · 21%
README

nut.js (Native UI Toolkit)

GitHub Actions
Master Create tagged release
Develop Create snapshot release

SonarCloud badge SonarCloud Coverage

Downloads per month @nut-tree/nut-js

Console - Developer Tool of the Week

Please visit

nutjs.dev

for detailed documentation and tutorials

About

<img src="https://github.com/nut-tree/nut.js/raw/master/.gfx/nut.png" alt="logo" width="200"/>

nut.js is a cross-platform native UI automation / testing tool.

It allows for native UI interactions via keyboard and / or mouse, but additionally gives you the possibility to navigate the screen based on image matching.

Sponsoring

nut.js is developed with community in mind.

A huge "Thank you!" goes out to all sponsors who make open source a bit more sustainable!

Demo

Check out this demo video to get a first impression of what nut.js is capable of.

nut.js demo video

Tutorials

Please consult the project website at nutjs.dev for in-depth tutorials

API Docs

nut.js provides public API documentation auto-generated by TypeDoc.

Community

Feel free to join our Discord community

Modules

This list gives an overview on currently implemented and planned functionality. It's work in progress and will undergo constant modification.

Clipboard

  • [x] Copy text to clipboard
  • [x] Paste text from clipboard

Keyboard

  • [x] Support for standard US keyboard layout
  • [x] Support for multimedia keys

Mouse

  • [x] Support for mouse movement
  • [x] Support for mouse scroll
  • [x] Configurable movement speed
  • [x] Mouse drag

Window

  • [x] List all windows
  • [x] Retrieve active window
  • [x] Retrieve window title
  • [x] Retrieve window size and position
  • [x] Focus window
  • [x] Resize window
  • [x] Reposition window

Screen

  • [x] Retrieve RGBA color information on screen
  • [x] Highlighting screen regions
  • [x] Find a single or multiple occurrences of an image on screen (requires an additional provider package like e.g. nut-tree/template-matcher)
  • [x] Wait for an image to appear on screen (requires an additional provider package like e.g. nut-tree/template-matcher)
  • [x] Find a single or multiple occurrences of text on screen (*)
  • [x] Wait for a piece of text to appear on screen (*)
  • [x] Find a single or multiple windows on screen (*)
  • [x] Wait for a window to appear on screen (*)
  • [x] Hooks to trigger actions based on detected text, images or windows (*)

(*) Requires an additional provider package, visit nutjs.dev for more info

Integration

  • [x] Jest
  • [x] Electron
  • [x] Custom log integration

Sample

The following snippet shows a valid nut.js example (using multiple addons):

"use strict";

const {
  mouse,
  screen,
  singleWord,
  sleep,
  useConsoleLogger,
  ConsoleLogLevel,
  straightTo,
  centerOf,
  Button,
  getActiveWindow,
} = require("@nut-tree/nut-js");
const {
  preloadLanguages,
  Language,
  LanguageModelType,
  configure,
} = require("@nut-tree/plugin-ocr");

configure({ languageModelType: LanguageModelType.BEST });

useConsoleLogger({ logLevel: ConsoleLogLevel.DEBUG });

screen.config.autoHighlight = true;
screen.config.ocrConfidence = 0.8;

function activeWindowRegion() {
  return getActiveWindow().then((activeWindow) => activeWindow.region);
}

(async () => {
  await preloadLanguages([Language.English], [LanguageModelType.BEST]);
  await sleep(5000);
  const result = await screen.find(singleWord("@nut-tree/nut-js"));
  await mouse.move(straightTo(centerOf(result)));
  await mouse.click(Button.LEFT);
  await screen.waitFor(singleWord("Native"), 15000, 1000, {
    providerData: { partialMatch: true },
  });
  const content = await screen.read({ searchRegion: activeWindowRegion() });
  console.log(content);
})();

Installation

Prerequisites

This section lists runtime requirements for nut.js on the respective target platform.

Windows

In case you're running Windows 10 N and want to use ImageFinder plugins, please make sure to have the Media Feature Pack installed.

macOS

On macOS, Xcode command line tools are required. You can install them by running

xcode-select --install

Permissions:

nut.js requires the executing application, e.g. your terminal, to be given both Accessibility and Screen Recording permissions.

Starting with release 2.3.0, nut.js will check for and request these permissions automatically:

<img src="https://github.com/nut-tree/nut.js/raw/develop/.gfx/permissions_popup.png" alt="Popup requesting screen recording permissions"/>

It will also give you a subtle hint in case permissions are lacking:

  • Accessibility: ##### WARNING! The application running this script is not a trusted process! Please visit https://github.com/nut-tree/nut.js#macos #####
  • Screen Recording: ##### WARNING! The application running this script is not allowed to capture screen content! Please visit https://github.com/nut-tree/nut.js#macos #####

Attention:

Prior to release 2.3.0 you'll have to grant these permissions manually.

Settings -> Security & Privacy -> Privacy tab -> Accessibility -> Add...

For example, if you want to execute your node script in e.g. iTerm2, you'd have to add iTerm.app to the list. When running your script from a built-in terminal in e.g. VSCode or IntelliJ, you'd have to add the respective IDE.

<img src="https://github.com/nut-tree/nut.js/raw/develop/.gfx/permissions.png" alt="accessibility permissions screen"/>

Linux

Depending on your distribution, Linux setups may differ.

In general, nut.js requires

  • libXtst

Installation on *buntu distributions:

sudo apt-get install libxtst-dev

Setups on other distributions might differ.

Attention:

At the moment nut.js only supports X11.

Wayland is NOT supported!

On e.g. Ubuntu you can switch to XWayland on your login screen as a workaround.

Install nut.js

Running

npm i @nut-tree/nut-js

or

yarn add @nut-tree/nut-js

will install nut.js and its required dependencies.

Snapshot releases

nut.js also provides snapshot releases which allows to test upcoming features.

Running

npm i @nut-tree/nut-js@next

or

yarn add @nut-tree/nut-js@next

will install the most recent development release of nut.js.

Attention: While snapshot releases are great to work with upcoming features before a new stable release, it is still a snapshot release. Please bear in mind that things might change and / or break on snapshot releases, so it is not recommended using them in production.

Extension points exported contracts — how you extend this code

ImageProcessor (Interface)
(no doc) [2 implementers]
core/provider-interfaces/lib/image-processor.interface.ts
WindowInterface (Interface)
(no doc) [2 implementers]
core/shared/lib/types/window.interface.ts
Screen (Interface)
(no doc) [1 implementers]
providers/libnut/libnut.d.ts
WindowApi (Interface)
(no doc) [1 implementers]
core/nut.js/lib/window-api.interface.ts
MouseProviderInterface (Interface)
(no doc) [2 implementers]
core/provider-interfaces/lib/mouse-provider.interface.ts
WindowElement (Interface)
(no doc)
core/shared/lib/types/window-element.interface.ts
Bitmap (Interface)
(no doc)
providers/libnut/libnut.d.ts
KeyboardConfig (Interface)
(no doc)
core/nut.js/lib/keyboard.class.ts

Core symbols most depended-on inside this repo

getLogProvider
called by 138
core/provider-interfaces/lib/provider-registry.interface.ts
error
called by 46
core/nut.js/lib/provider/log/noop-log-provider.class.ts
debug
called by 42
core/nut.js/lib/provider/log/noop-log-provider.class.ts
info
called by 41
core/nut.js/lib/provider/log/noop-log-provider.class.ts
find
called by 25
core/shared/lib/types/window.interface.ts
toString
called by 22
core/shared/lib/objects/size.class.ts
sleep
called by 19
core/nut.js/lib/sleep.function.ts
getMouse
called by 18
core/provider-interfaces/lib/provider-registry.interface.ts

Shape

Method 272
Function 84
Class 64
Interface 33
Enum 6

Languages

TypeScript100%

Modules by API surface

core/provider-interfaces/lib/provider-registry.interface.ts42 symbols
core/nut.js/lib/screen.class.ts22 symbols
providers/libnut/lib/libnut-mouse.class.ts18 symbols
core/nut.js/lib/window.class.ts18 symbols
core/nut.js/lib/mouse.class.ts18 symbols
core/provider-interfaces/lib/mouse-provider.interface.ts15 symbols
core/nut.js/lib/provider/provider-registry.class.ts15 symbols
providers/libnut/lib/libnut-window.class.ts11 symbols
providers/libnut/lib/libnut-keyboard.class.ts11 symbols
core/shared/lib/types/window.interface.ts11 symbols
core/nut.js/lib/provider/log/console-log-provider.class.ts11 symbols
providers/libnut/lib/libnut-screen.class.ts10 symbols

Dependencies from manifests, versioned

@nut-tree/configsworkspace:* · 1×
@nut-tree/default-clipboard-providerworkspace:* · 1×
@nut-tree/libnutworkspace:* · 1×
@nut-tree/libnut-darwin2.7.1 · 1×
@nut-tree/libnut-linux2.7.1 · 1×
@nut-tree/libnut-win322.7.1 · 1×
@nut-tree/nl-matcher2.2.0 · 1×
@nut-tree/nut-jsworkspace:* · 1×
@nut-tree/provider-interfacesworkspace:* · 1×
@nut-tree/sharedworkspace:* · 1×
@playwright/test1.41.2 · 1×
@types/jest29.5.12 · 1×

For agents

$ claude mcp add nut.js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact