MCPcopy Index your code
hub / github.com/SylvanFranklin/launchctl

github.com/SylvanFranklin/launchctl @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
9 symbols 17 edges 3 files 5 documented · 56%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Launchctl

Tiny Rust wrapper library for MacOS service launcher launchctl. This library offers a more intuitive interface for managing services on MacOS, cuz I'm not finna syscall that confusing shi every time I want to start a service. Other Rust crates exist for interfacing with cross platform launch services. This library is specifically for MacOS. For more info about launchctl and launchd see the official apple docs.

Install

cargo add launchctl

[!NOTE] Coming soon is a CLI version which will make it easier to automate creating a service.

Usage

The Service struct is the main entry point of this library. It uses a bon builder.

fn main() {
    // basic construction of a service
    let basic_service = Service::builder()
        .name("com.<owner name>.<binary name>")
        .build();

    // more advanced construction of a service
    let more_custom = Service::builder()
        .name("com.<owner name>.<binary name>")
        .
        .build();

    // create a .plist file for the service
    // ...

    basic.start().unwrap();
    custom.stop().unwrap();
}

Limitations

Currently this crate does not support creating or modifying plist files. There are other crates that can give you this behavior https://github.com/koenichiwa/launchd, or you can hard code them as strings which is what I prefer.

Here is an example of how I do that in my srhd crate.

pub fn install(ctl: &launchctl::Service) -> Result<(), Error> {
    let plist = format!(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
    <key>Label</key>
    <string>{}</string>
    <key>ProgramArguments</key>
    <array>
        <string>{}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
        <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
         <false/>
         <key>Crashed</key>
         <true/>
    </dict>
    <key>StandardOutPath</key>
    <string>/tmp/srhd_sylvanfranklin.out.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/srhd_sylvanfranklin.err.log</string>
    <key>ProcessType</key>
    <string>Interactive</string>
    <key>Nice</key>
    <integer>-20</integer>
</dict>
</plist>",
        ctl.name,
        ctl.bin_path.to_str().unwrap(),
    );

    Ok(fs::write(ctl.plist_path.clone(), plist)?)
}

Contribution

Bro I love when people contribute or even submit issues. It's good for everyone's career and understanding of everything, by all means open an issue or a PR!

Core symbols most depended-on inside this repo

cmd
called by 6
src/lib.rs
is_bootstrapped
called by 2
src/lib.rs
stop
called by 1
src/lib.rs
start
called by 1
src/lib.rs
create_log_files
called by 1
src/lib.rs
restart
called by 0
src/lib.rs

Shape

Method 6
Function 2
Class 1

Languages

Rust100%

Modules by API surface

src/lib.rs7 symbols
src/tests/service.rs2 symbols

For agents

$ claude mcp add launchctl \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact