in tauri, get the currently open apps in dock in rust

To get the currently open apps in the dock on macOS, Linux, and Windows, you can use the tauri::command module to execute the appropriate command for each operating system.

Here's an example Rust code snippet that retrieves the currently open apps in the dock for each OS:

main.rs
use tauri::api::command::{Command, CommandArg};

pub fn get_open_apps() -> Vec<String> {
    let cmd = match std::env::consts::OS {
        "macos" => Command::new("osascript"),
        "windows" => Command::new("powershell"),
        "linux" => Command::new("xdotool"),
        _ => panic!("unsupported OS"),
    };

    let output = cmd.arg(CommandArg::from("some-dock-command")).output().unwrap();

    let stdout = String::from_utf8_lossy(&output.stdout).to_string();

    //parse `stdout` and extract open apps information based on the OS

    let open_apps = vec!["app1".to_string(), "app2".to_string()];

    open_apps
}
628 chars
21 lines

Note that you will need to replace "some-dock-command" in the code snippet with the appropriate command for retrieving the open apps on each OS. Additionally, you will need to implement the logic to parse the stdout for each OS and extract the open apps information.

related categories

gistlibby LogSnag