| Crates.io | auto-launch |
| lib.rs | auto-launch |
| version | 0.6.0 |
| created_at | 2022-01-14 19:10:47.426223+00 |
| updated_at | 2026-01-10 18:37:55.393402+00 |
| description | Auto launch any application or executable at startup. Supports Windows, macOS, and Linux. |
| homepage | |
| repository | https://github.com/zzzgydi/auto-launch.git |
| max_upload_size | |
| id | 514005 |
| size | 76,006 |
Auto launch any application or executable at startup. Supports Windows, macOS (Launch Agent, AppleScript, or SMAppService), and Linux.
How does it work? See Teamwork/node-auto-launch for details.
If you find any bugs, welcome to PR or issue.
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_macos_launch_mode(MacOSLaunchMode::LaunchAgent)
.build()
.unwrap();
auto.enable().unwrap();
auto.is_enabled().unwrap();
auto.disable().unwrap();
auto.is_enabled().unwrap();
}
Linux supports two ways to achieve auto launch:
.desktop files in ~/.config/autostart/ (default)~/.config/systemd/user/
systemctl --user enable to enable the service.systemctl to be available in the environment.use auto_launch::{AutoLaunch, LinuxLaunchMode};
fn main() {
let app_name = "the-app";
let app_path = "/path/to/the-app";
// Use XDG Autostart (default method)
let auto = AutoLaunch::new(app_name, app_path, LinuxLaunchMode::XdgAutostart, &[] as &[&str]);
// Or use systemd user service
// let auto = AutoLaunch::new(app_name, app_path, LinuxLaunchMode::Systemd, &[] 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 supports three ways to achieve auto launch:
~/Library/LaunchAgents/ (default)Note:
app_path should be an absolute path and exists. Otherwise, it will cause an error when enable.app_name should be same as the basename of app_path, or it will be corrected automatically.--hidden and --minimized in args are valid, which means that hide the app on launch.app_name and app_path can be empty strings because it registers the running app.use auto_launch::{AutoLaunch, MacOSLaunchMode};
fn main() {
let app_name = "the-app";
let app_path = "/path/to/the-app.app";
// Use Launch Agent (default method)
let auto = AutoLaunch::new(app_name, app_path, MacOSLaunchMode::LaunchAgent, &[] as &[&str], &[] as &[&str], "");
// Or use AppleScript
// let auto = AutoLaunch::new(app_name, app_path, MacOSLaunchMode::AppleScript, &[] as &[&str], &[] as &[&str], "");
// Or use SMAppService (macOS 13+)
// let auto = AutoLaunch::new(app_name, app_path, MacOSLaunchMode::SMAppService, &[] as &[&str], &[] 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();
}
On Windows, it will add registry entries under:
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (system)\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (current user)\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run (Task Manager status)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.
Enable behavior is controlled by WindowsEnableMode:
Dynamic (default): try system-wide, fall back to current user on access deniedCurrentUser: write to current user onlySystem: write to system only (admin required)use auto_launch::{AutoLaunch, WindowsEnableMode};
fn main() {
let app_name = "the-app";
let app_path = "C:\\path\\to\\the-app.exe";
let auto = AutoLaunch::new(app_name, app_path, WindowsEnableMode::Dynamic, &[] 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();
}
MIT License. See the License file for details.
The project is based on node-auto-launch.