-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any idea why running ~empty Finder calls could time out with "Finder got an error: AppleEvent timed out" #2
Comments
Hello @eugenesvk. Thanks for reporting this issue, I'll take a look into it. |
Thanks, meanwhile I've sprinkeld a few prints in the script, and when it bugs it seems to always bug before setting to selection
|
After some experimentation I'm really confused :) So when calling OSAKit API via rust, Finder sometimes timeouts. I've even write an alternative approach using Carbon directly, but it had the same behavior. I've tried it with I've tried the same using mono / C# via Carbon API and it also works just fine. |
Yeah, the cli No idea, but could this in any way be tied to the deprecated icrate that's replaced by https://crates.io/crates/objc2-osa-kit? Or maybe thread issues??? https://stackoverflow.com/questions/46972115/objective-c-and-applescript-timeout-events-threads |
@eugenesvk yeah, the threads were the correct guess! Here is the use std::{thread, time};
use osakit::{Language, Script};
pub fn main() {
let script_text = format!(
r#"
tell application "Finder"
set Trash_items to selection
end tell
return "empty string"
"#
);
let mut script = Script::new_from_source(Language::AppleScript, &script_text);
script.compile().unwrap();
let ten_millis = time::Duration::from_millis(10);
for i in 0..1000 {
println!("{i} sleeping");
println!("{:?}", script.execute().unwrap());
thread::sleep(ten_millis);
}
} It runs all 1000 iterations without problems. Looks like the main requirement for OSAKit is to be on the main thread. And tests are run on separate threads, therefore they fail sometimes. |
Oh, so it's purely a testing issue! Thanks for finding out! Do you know of any way to force the main thread for tests? It seems that there is a Rust issue rust-lang/rust#104053 suggesting the defaults don't support that |
Looks like this problem was many times discussed within the context of I've created a feature request in |
I've tried with the mentioned |
Several additions:
|
I'm using your crate to get Finder to do a few simple things while being able to parse its output.
This is the full test code I'm running (src), all it does is invokes a short script 10 times, which asks Finder to save the selection to a variable, and return the same string.
So there is no work happening to timeout for 2 mins. And locally this runs mostly fine, but then from time to time it would bug on some iteration (maybe even the first 1, maybe the 9th)
Same thing with CI, though it seems to fail more frequently? For example, here the logs tell that loop 9 failed
(I don't think the previous version of using osascript command had such issues, but haven't tested that one much, it anyway doesn't quote the output properly to parse list of files with arbitrary names)
The text was updated successfully, but these errors were encountered: