Environment:AI QL Tuui Nut JS
| Knowledge Sources | |
|---|---|
| Domains | Automation, Desktop_Automation, Cross_Platform |
| Last Updated | 2026-10-24 20:38 GMT |
Overview
Cross-platform desktop automation library providing keyboard and mouse simulation for text grabbing, pasting, and caret movement on macOS, Windows, and Linux.
Description
@nut-tree-fork/nut-js (>= 4.2.6) is a fork of the nut-js desktop automation library. It provides keyboard input simulation (key press, type), mouse control, and clipboard integration. In tuui, it is loaded dynamically via await import('@nut-tree-fork/nut-js') at runtime — if the native module fails to load, the automator falls back to platform-specific scripting (AppleScript on macOS, VBScript on Windows). The library is used as the primary mechanism for simulating Ctrl+C/Cmd+C to copy selected text, Ctrl+V/Cmd+V to paste, and Delete/Enter for caret manipulation.
Usage
Use this environment for any implementation in the src/main/aid/ directory that performs GUI automation. nut-js is the primary automator; AppleScript/VBScript serve as fallbacks.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | macOS, Windows, or Linux | Native modules are platform-specific |
| Hardware | Keyboard and display | Required for GUI automation |
| macOS | Accessibility permissions | App must be granted Accessibility access in System Settings |
| Linux | X11 or Wayland | Display server required for keyboard simulation |
Dependencies
NPM Packages
- `@nut-tree-fork/nut-js` >= 4.2.6
- `applescript` >= 1.0.0 (macOS fallback)
- `@el3um4s/run-vbs` >= 1.1.2 (Windows fallback)
Platform-Specific Native Dependencies
- macOS: Requires Accessibility permissions (System Settings > Privacy & Security > Accessibility)
- Windows: No special permissions required for keyboard simulation
- Linux: X11 development headers (libxtst, libxinerama) for native module build
Credentials
No credentials required.
Quick Install
npm install @nut-tree-fork/nut-js@^4.2.6 applescript@^1.0.0 @el3um4s/run-vbs@^1.1.2
Code Evidence
Dynamic import with graceful fallback from `src/main/aid/nut.ts:11-27`:
protected async setup() {
if (nut) return true
if (nut === null) return false
try {
const nutPackage = '@nut-tree-fork/nut-js'
nut = await import(nutPackage)
return true
} catch {
console.log('Error loading nutjs. Automation not available.')
nut = null
return false
}
}
Platform-dispatching constructor from `src/main/aid/automator.ts:12-18`:
constructor() {
if (process.platform === 'darwin') {
this.automator = new MacosAutomator()
} else if (process.platform === 'win32') {
this.automator = new WindowsAutomator()
} else {
this.automator = new NutAutomator()
}
}
macOS-specific keyboard config from `src/main/aid/macos.ts:179-183`:
protected async setupNut() {
const rc = await super.setup()
if (rc) {
this.nut().keyboard.config.autoDelayMs = 25
}
return rc
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Error loading nutjs. Automation not available.` | Native module not built/loaded | Run npm rebuild or npm install
|
| `nutjs not loaded` | setup() returned false |
Check native dependencies; fall back to AppleScript/VBScript |
| Automation silently fails on macOS | Missing Accessibility permission | Grant Accessibility access to the app in System Settings |
Compatibility Notes
- macOS: Uses
Key.LeftCmdas command key. Auto-delay set to 25ms. Falls back to AppleScript for all operations. - Windows: Uses
Key.LeftControlas command key. Falls back to VBScript (@el3um4s/run-vbs). - Linux: Uses
Key.LeftControlas command key. No fallback scripting available. Delay is 150ms. - MAS builds: Automation is disabled entirely; Commander shows a limitations dialog.
- Debug mode: The
wait()helper uses busy-wait instead ofsetTimeouton non-macOS in debug mode due to an unresolved issue.