Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vilicvane/startup-run
Run scripts at startup with ease.
https://github.com/vilicvane/startup-run
Last synced: 20 days ago
JSON representation
Run scripts at startup with ease.
- Host: GitHub
- URL: https://github.com/vilicvane/startup-run
- Owner: vilicvane
- License: mit
- Created: 2023-10-04T16:07:20.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-15T16:28:25.000Z (10 months ago)
- Last Synced: 2024-11-30T15:42:01.650Z (23 days ago)
- Language: TypeScript
- Homepage:
- Size: 171 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM version](https://img.shields.io/npm/v/startup-run?color=%23cb3837&style=flat-square)](https://www.npmjs.com/package/startup-run)
[![Repository package.json version](https://img.shields.io/github/package-json/v/vilic/startup-run?color=%230969da&label=repo&style=flat-square)](./package.json)
[![MIT License](https://img.shields.io/badge/license-MIT-999999?style=flat-square)](./LICENSE)# startup-run
Run **command-line scripts** at startup with ease.
Supports **Windows**, **macOS** and **Linux** (Desktop).
## Features
- Run non-GUI scripts at startup, **hidden**.
- Run as **current user** on Windows (running as service would cause problems for scripts with UI interactions).
- Log to file.
- Auto restart (respawn) on exit.## Installation
```bash
npm install startup-run
```## Usage
```js
import {StartupRun} from 'startup-run';const run = StartupRun.create('awesome-script');
await run.enable();
await run.disable();
await run.isEnabled(); // boolean
await run.start(); // start daemon.
await run.stop(); // stop daemon.
// Setup to enable/disable startup, this exits current process if either
// `enable` or `disable` is true.
await run.setup({
enable: process.argv.includes('--startup'),
disable: process.argv.includes('--disable-startup'),
});StartupRun.daemonSpawned; // boolean, is current process spawned by daemon.
```### Default Options
```js
const run = StartupRun.create('', {
command: process.execPath,
args: process.argv.slice(1),
cwd: process.cwd(),
env: {},
log: true,
respawn: true,
});
```## Implementations
### Windows
On Windows, it adds a startup item to registry at `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run`, thus starting the script at login as current user.
> Solutions like `pm2` run scripts as service, which would cause problems for scripts with UI interactions.
Tested on:
- Windows 11
### macOS
On macOS, it adds a `.plist` file to `~/Library/LaunchAgents`.
Tested on:
- macOS Sonoma 14
### Linux
On Linux, it adds a `.desktop` file to `~/.config/autostart`.
Tested on:
- Ubuntu 22.04 (Desktop)
## Third Parties
### node-auto-launch
Package **startup-run** is inspired by [node-auto-launch](https://github.com/Teamwork/node-auto-launch) but for different scenarios. While `node-auto-launch` focuses on GUI applications, **startup-run** focuses on scripts instead.
It refers some implementation details from `node-auto-launch`, but is overall refactored or rewritten to better serve its own design goals.
## License
MIT License.