Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Native bindings to launchctl commands for node
C++ JavaScript Shell Python

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
src
.gitignore
Makefile
README.md
binding.gyp
package.json
test.js

README.md

node-launchctl

Provides native bindings to launchctl commands

Please note that this module is in the earlier stages. It could change.

Install

    npm install launchctl

API

    var launchctl = require('launchctl')

list

List all jobs

    launchctl.list(function(err, jobs){
        if (err) {
            console.error(err);
        } else {
            console.log(jobs);
        }
    });

Will return something like:

    [
        { 
            label: 'com.apple.KerberosHelper.LKDCHelper',
            pid: '-',
            status: 1
        },
        {
            label: 'com.apple.tccd',
            pid: 304,
            status: '-'
        },
        ...
    ]

List all jobs matching regex

    launchctl.list(/^com.apple.(.*)/, function(err, jobs) {
        if (err) {
            console.error(err);
        } else {
            console.log(jobs);
        }
    });

Will return an array of jobs like above

List a job by name

    launchctl.list('com.apple.Dock.agent', function(err, job) {
        if (err) {
            console.error(err);
        } else {
            console.log(job);   
        }
    });

Will return something like:

    {
        Label: 'com.apple.Dock.agent',
        LimitLoadToSessionType: 'Aqua',
        OnDemand: 1,
        LastExitStatus: 256,
        PID: 6601,
        TimeOut: 30,
        Program: '/System/Library/CoreServices/Dock.app/Contents/MacOS/Dock',
        MachServices: {
            'com.apple.dock.appstore': 'mach-port-object',
            'com.apple.dock.server': 'mach-port-object',
            'com.apple.dock.fullscreen': 'mach-port-object',
            'com.apple.dock.downloads': 'mach-port-object',
            'com.apple.dock.notificationcenter': 'mach-port-object'
        },
        PerJobMachServices: {
            'com.apple.CFPastboardClient': 'mach-port-object',
            'com.apple.tsm.portname': 'mach-port-object',
            'com.apple.coredrag': 'mach-port-object',
            'com.apple.axserver': 'mach-port-object'
        }
    }

listSync

Synchronous version of list

  • returns either an array of jobs or a job object

start

Start job with given label

    launchctl.start('com.apple.Dock.agent', function(err){
        if (err) {
            console.error(err);
        } else {
            console.log('Successfully started job');
        }
    });

startSync

Synchronous version of start


stop

Stop job with given label

    launchctl.stop('homebrew.mxcl.redis', function(err) {
        if (err) {
            console.error(err);
        } else {
            console.log('Successfully stopped job');
        }
    });

stopSync

Synchronous version of stop


restart

NOTE: Keep in mind what stop does in launchctl. If the process is set to be kept alive, then restart is not necessary. Stop will work, because it will restart it as soon as it stops it.

Restart job with given label

    launchctl.restart('homebrew.mxcl.redis', function(err){
        if (err) {
            console.error(err);
        } else {
            console.log('Successfully restarted job');
        }
    });

restartSync

Synchronous version of restart


remove

Remove job with given label

    launchctl.remove('homebrew.mxcl.redis', function(err) {
        if (err) {
            console.log(err);
        } else {
            console.log('Successfully removed job');
        }
    });

removeSync

Synchronous version of remove

TODO

Make API more complete

  • load
  • unload
  • submit

Contributions

  • Please feel free to fork/contribute :]
Something went wrong with that request. Please try again.