How to retrieve the selected file after the user has pressed the Tauri Mac shortcut? #8505
-
I am trying to obtain the file path when the user selects a file and presses "Cmd+Shift+R" in the finder. I have successfully registered the shortcut, and it is working. However, I am unsure of how to obtain the file path of the selected file. #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::GlobalShortcutManager;
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello ->, {}!", name)
}
fn main() {
// setup the shortcut
tauri::Builder::default()
.setup(|app| {
// #[cfg(target_os = "macos")]
// app.set_activation_policy(tauri::ActivationPolicy::Accessory);
let mut shortcut = app.global_shortcut_manager();
shortcut
.register("Cmd+Shift+R", move || {
println!("Cmd+Shift+R pressed");
})
.unwrap_or_else(|err| println!("{:?}", err));
Ok(())
})
.invoke_handler(tauri::generate_handler![greet])
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(|_app_handle, event| match event {
tauri::RunEvent::ExitRequested { api, .. } => {
api.prevent_exit();
}
_ => {}
})
} UPDATE: I wrote a small AppleScript to do this, although I would love to know if this is the right way to accomplish the task?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Probably the best you get since this doesn't seem like something macos actually wants you to do (no good explicit apis for this). And if it works, can it really be wrong? |
Beta Was this translation helpful? Give feedback.
Probably the best you get since this doesn't seem like something macos actually wants you to do (no good explicit apis for this). And if it works, can it really be wrong?