Expand description
§SMAppService-RS
A Rust wrapper for macOS’s ServiceManagement framework, specifically the SMAppService API.
§Overview
The ServiceManagement framework in macOS provides a way for applications to manage system services. This library wraps the objc2-service-management API in a Rust-friendly interface, allowing to:
- Register applications as login items
- Register and manage launch agents and daemons from the application bundle
- Check the status of registered services
§Example Usage
use smappservice_rs::{AppService, ServiceType, ServiceStatus};
// Register the current application as a login item
let app_service = AppService::new(ServiceType::MainApp);
match app_service.register() {
Ok(()) => println!("Application registered successfully as login item!"),
Err(e) => eprintln!("Failed to register application: {}", e),
}
// Check the registration status
let status = app_service.status();
println!("Service status: {}", status);
// Register a LaunchAgent
let agent_service = AppService::new(ServiceType::Agent {
plist_name: "com.example.myapp.agent.plist"
});
if let Err(e) = agent_service.register() {
eprintln!("Failed to register agent: {}", e);
}
// Open System Settings to manage login items
AppService::open_system_settings_login_items();
// Register a LaunchDaemon
let daemon_service = AppService::new(ServiceType::Daemon {
plist_name: "com.example.myapp.daemon.plist"
});
if let Err(e) = daemon_service.register() {
eprintln!("Failed to register daemon: {}", e);
}
// Register a helper application as a login item
let login_item = AppService::new(ServiceType::LoginItem {
identifier: "com.example.helper"
});
if let Err(e) = login_item.register() {
eprintln!("Failed to register login item: {}", e);
}
Structs§
- AppService
- The main struct for interacting with macOS’s ServiceManagement framework.
Enums§
- Service
Management Error - Represents errors that can occur when registering or unregistering services.
- Service
Status - Represents the status of a service registration.
- Service
Type - Represents the various types of services that can be registered with the ServiceManagement framework.