| Crates.io | nsworkspace |
| lib.rs | nsworkspace |
| version | 0.2.0 |
| created_at | 2025-09-02 15:57:32.002904+00 |
| updated_at | 2025-09-10 08:59:15.913624+00 |
| description | A library for listening to NSWorkspace notifications. |
| homepage | https://github.com/mishamyrt/nsworkspace-rs |
| repository | https://github.com/mishamyrt/nsworkspace-rs |
| max_upload_size | |
| id | 1821301 |
| size | 30,010 |
A library for listening to NSWorkspace notifications. It provides a high-level interface for listening to notifications.
NSWorkspace notificationsEvent enum: activate/deactivate, launch/terminate, hide/unhideNotificationListener bitmask flagsstd::sync::mpscFirst, add package to your Cargo.toml:
[dependencies]
nsworkspace = "0.1.0"
Then, you can use the library to listen to NSWorkspace notifications.
use std::thread;
use nsworkspace::{events::NotificationListener, monitor::Monitor};
fn main() {
let Some((monitor, events)) = Monitor::new() else {
eprintln!("NSWorkspace monitor must be created on the main thread");
return;
};
// Consume events on a background thread
thread::spawn(move || {
for event in events {
println!("Event: {event:?}");
}
});
// Subscribe to some notifications
let listeners = NotificationListener::DidActivateApplication
| NotificationListener::DidLaunchApplication
| NotificationListener::DidTerminateApplication;
monitor.subscribe(listeners);
// Optional: print current frontmost app
println!("Active application: {:?}", monitor.get_active_application());
// Start the AppKit run loop (blocking)
monitor.run();
}
NSWorkspace)