Giter Club home page Giter Club 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

user-startup's People

Contributors

adriancooney avatar noamokman avatar typicode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

user-startup's Issues

Windows startup fails on machines with AntiVirus programs running

It appears at least on MS Defender and Symantec End Point security, the VBScript is ignored in the Startup folder.

There is a way to add a user-specific registry entry that doesn't require Admin to add a Windows startup process. This works with these AV programs running. To do this, I used the npm module winreg. If you'd be interested in a way to register a platform specific override for the platform strategy, and a new strategy, I can put together a pull request.

It may require an alternative 'export' style.

Thoughts?

Darwin wrong launchctl load

node_modules/user-startup/lib/startup/darwin.js
line 44:
cp.execSync('launchctl load ' + name);

must be
cp.execSync('launchctl load ' + file);

you load the service plist file, then you can start the service by name

Win64

Win64 crash...
you must copy win32.js to win64.js or just load the same file for both platforms

Object #<Object> has no method 'execSync'

This error occured when trying to install and run hotel for the first time. Didn't post in hotel because it seems like a user-startup module error:

hotel start

/usr/local/lib/node_modules/hotel/node_modules/user-startup/lib/startup/darwin.js:34
  cp.execSync('launchctl load ' + file);
     ^
TypeError: Object #<Object> has no method 'execSync'
    at Object.create (/usr/local/lib/node_modules/hotel/node_modules/user-startup/lib/startup/darwin.js:34:6)
    at Object.start (/usr/local/lib/node_modules/hotel/lib/cli/daemon.js:22:11)
    at module.exports (/usr/local/lib/node_modules/hotel/lib/cli/index.js:32:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/hotel/bin/index.js:2:22)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

npm version: 1.4.21
node version: 0.10.30

Script doesn't start in Ubuntu

I'm using this module to startup an script, but I found an error related to file permission.

I suggest add exec file permission to solve this problem, as I requested in #9

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.