#startup #launch #login #login-items

auto-launch

Auto launch any application or executable at startup. Supports Windows, macOS, and Linux.

6 releases (breaking)

0.5.0 Sep 10, 2023
0.4.0 Sep 10, 2022
0.3.0 Aug 24, 2022
0.2.0 Jan 15, 2022
0.1.1 Jan 14, 2022

#252 in Authentication

Download history 2726/week @ 2024-07-04 3463/week @ 2024-07-11 2422/week @ 2024-07-18 3371/week @ 2024-07-25 4435/week @ 2024-08-01 5649/week @ 2024-08-08 4467/week @ 2024-08-15 3272/week @ 2024-08-22 3827/week @ 2024-08-29 4149/week @ 2024-09-05 2974/week @ 2024-09-12 2856/week @ 2024-09-19 3561/week @ 2024-09-26 3258/week @ 2024-10-03 3308/week @ 2024-10-10 3611/week @ 2024-10-17

14,229 downloads per month
Used in 2 crates

MIT license

27KB
347 lines

Auto Launch

Crates.io API reference License

Auto launch any application or executable at startup. Supports Windows, Mac (via AppleScript or Launch Agent), and Linux.

How does it work? See Teamwork/node-auto-launch for details.

If you find any bugs, welcome to PR or issue.

Usage

The parameters of AutoLaunch::new are different on each platform. See the function definition or the demo below for details.

AutoLaunchBuilder helps to eliminate the constructor difference on various platforms.

use auto_launch::*;

fn main() {
    let auto = AutoLaunchBuilder::new()
        .set_app_name("the-app")
        .set_app_path("/path/to/the-app")
        .set_use_launch_agent(true)
        .build()
        .unwrap();

    auto.enable().unwrap();
    auto.is_enabled().unwrap();

    auto.disable().unwrap();
    auto.is_enabled().unwrap();
}

Linux

use auto_launch::AutoLaunch;

fn main() {
    let app_name = "the-app";
    let app_path = "/path/to/the-app";
    let auto = AutoLaunch::new(app_name, app_path, &[] as &[&str]);

    // enable the auto launch
    auto.enable().is_ok();
    auto.is_enabled().unwrap();

    // disable the auto launch
    auto.disable().is_ok();
    auto.is_enabled().unwrap();
}

macOS

macOS supports two ways to achieve auto launch (via AppleScript or Launch Agent). When the use_launch_agent is true, it will achieve by Launch Agent, otherwise by AppleScript.

Note:

  • The app_path should be a absolute path and exists. Otherwise, it will cause an error when enable.
  • In case using AppleScript, the app_name should be same as the basename of app_path, or it will be corrected automatically.
  • In case using AppleScript, only --hidden and --minimized in args are valid, which means that hide the app on launch.
use auto_launch::AutoLaunch;

fn main() {
    let app_name = "the-app";
    let app_path = "/path/to/the-app.app";
    let auto = AutoLaunch::new(app_name, app_path, false, &[] as &[&str]);

    // enable the auto launch
    auto.enable().is_ok();
    auto.is_enabled().unwrap();

    // disable the auto launch
    auto.disable().is_ok();
    auto.is_enabled().unwrap();
}

Windows

On Windows, it will add registry entries under \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run and \HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run.

It will also detect if startup is disabled inside Task Manager or the Windows settings UI, and can re-enable after being disabled in one of those.

use auto_launch::AutoLaunch;

fn main() {
    let app_name = "the-app";
    let app_path = "C:\\path\\to\\the-app.exe";
    let auto = AutoLaunch::new(app_name, app_path, &[] as &[&str]);

    // enable the auto launch
    auto.enable().is_ok();
    auto.is_enabled().unwrap();

    // disable the auto launch
    auto.disable().is_ok();
    auto.is_enabled().unwrap();
}

License

MIT License. See the License file for details.

Acknowledgement

The project is based on node-auto-launch.

Dependencies

~0.3–1.1MB
~21K SLoC