Crate launchd

source ·
Expand description

A Rust library for creating and parsing Launchd files.

It’s still in early development and all help is welcome.

Example

use launchd::{CalendarInterval, Error, Launchd};

fn main() -> Result<(), Error> {
    let ci = CalendarInterval::default()
        .with_hour(12)?
        .with_minute(10)?
        .with_weekday(7)?;

    let launchd = Launchd::new("LABEL", "./foo/bar.txt")?
            .with_user_name("Henk")
            .with_program_arguments(vec!["Hello".to_string(), "World!".to_string()])
            .with_start_calendar_intervals(vec![ci])
            .disabled();

    #[cfg(feature="io")] // Default
    return launchd.to_writer_xml(std::io::stdout());

    #[cfg(not(feature="io"))] // If you don't want to build any optional dependencies
    return Ok(());
}

Results in:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>LABEL</string>
        <key>Disabled</key>
        <true />
        <key>UserName</key>
        <string>Henk</string>
        <key>Program</key>
        <string>./foo/bar.txt</string>
        <key>ProgramArguments</key>
        <array>
                <string>Hello</string>
                <string>World!</string>
        </array>
        <key>StartCalendarIntervals</key>
        <array>
                <dict>
                        <key>Minute</key>
                        <integer>10</integer>
                        <key>Hour</key>
                        <integer>12</integer>
                        <key>Weekday</key>
                        <integer>7</integer>
                </dict>
        </array>
</dict>
</plist>

Re-exports

Modules

Structs

  • Representation of a CalendarInterval
  • Representation of a launchd.plist file. The definition of which can be found here.

Enums