#macos #service #system #launcher

launchctl

A simple library for managing system services on MacOS

3 unstable releases

new 0.2.1 Oct 29, 2024
0.1.1 Oct 29, 2024
0.1.0 Oct 29, 2024

#76 in macOS and iOS APIs

Download history 314/week @ 2024-10-27

314 downloads per month
Used in srhd

MIT license

8KB
84 lines

Launchctl

Tiny Rust wrapper library for MacOS service launcher launchctl. This library offers a more intuitive interface for managing services on MacOS. Other Rust crates exist for interfacing with cross platform launch services, I just wanted one that zeroed in on MacOS. For more info about launchctl and launchd see the official apple docs.

Limitations

Currently this crate does not support creating or modifying plist files. There are other crates that can give you this behavior, or you can hard code them as strings.

Usage

(see docs.rs for more info)

fn main() {
    // basic construction of a service
    let basic = Service::new("com.<owner>.<binary>", PathBuf::from("/bin/ls"));

    // more advanced construction of a service
    let custom = Service {
        name: "com.<owner>.<binary>".to_string(),
        domain_target: "gui/501".to_string(),
        service_target: "gui/501/com.<owner>.<binary>".to_string(),
        uid: "501".to_string(),
        bin_path: "/bin/ls".into(),
        plist_path: "/Library/LaunchAgents/com.<owner>.<binary>.plist".to_string(),
        error_log_path: "/tmp/<binary>_<user>.err.log".to_string(),
        out_log_path: "/tmp/<binary>_<user>.out.log".to_string(),
    };

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

    basic.start().unwrap();
}

Installation


cargo add launchctl

No runtime deps