Code Monkey home page Code Monkey logo

user-startup's Introduction

user-startup Build Status npm version

Automatically run commands when the user logs in. Used in hotel and stop-server.

  • No admin privileges required
  • Cross-platform (OS X, Linux and Windows)

Install

npm install user-startup --save

Usage

Create a new instance.

const Startup = require('user-startup')
let startup

try {
  startup = Startup()
} catch (err) {
  // Unsupported platform
}

Add startup script but doesn't spawn process. Use create to create startup file and process at the same time.

startup.create(
  'my-script', // id
  process.execPath, // cmd
  ['/some/path/app.js'], // args
  '/some/path/out.log' // out
)

Remove startup script.

startup.remove('my-script')

Note: you should check that root isn't running this code to avoid startup scripts being created in root's home directory. Use sudo-block or is-root.

API

Startup()

Creates a new instance. Throws an error if platform isn't OS X, Linux or Windows.

add(id, cmd[, args[, out]])

  • id <String> id
  • cmd <String> command
  • args <Array> optional list of string arguments
  • out <String> optional path to output file (directory needs to exist before)

Creates startup script.

create(id, cmd[, args[, out]])

Creates a startup script and spawns process.

remove(id)

Removes startup script.

dir

Returns startup script directory.

getFile(id)

Returns startup script path.

How it works

  • On OS X, it creates a plist file in ~/Library/LaunchAgents
  • On Linux, it creates a desktop file in ~/.config/autostart
  • On Windows, it creates a vbs script in AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

License

MIT - Typicode

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.