Skip to content
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

No AXUIElement #624

Closed
aurexav opened this issue May 30, 2024 · 4 comments
Closed

No AXUIElement #624

aurexav opened this issue May 30, 2024 · 4 comments
Labels
A-framework Affects the framework crates and the translator for them question Further information is requested

Comments

@aurexav
Copy link

aurexav commented May 30, 2024

First, I apologize for opening a question here.

Can I use this crate to get the currently selected text?

I did find fn accessibilityFocusedUIElement(&self, ..) and objc2_app_kit::NSAccessibilityFocusedUIElementAttribute. But I couldn't find AXUIElement. So, how to obtain the &self NSObjectNSAccessibility? Then I can call accessibilityFocusedUIElement on it.

@madsmtm
Copy link
Owner

madsmtm commented May 31, 2024

First, I apologize for opening a question here.

No problem, please do!

No AXUIElement

AXUIElement comes from the ApplicationServices framework, which is why it is not defined just by importing AppKit.

That framework in particular is "CoreFoundation-like", and is not yet supported, see #556.

Can I use this crate to get the currently selected text?

Hmm, I'm not too familiar with the accessibility frameworks, but if you have e.g. a NSView, I believe you can just import NSObjectNSAccessibility, and then you should be able to call accessibilityFocusedUIElement?

In any case, I can recommend the AccessKit project, they abstract a lot of this for you, and their source code probably contain similar things as what you're trying to do.

@madsmtm madsmtm added question Further information is requested A-framework Affects the framework crates and the translator for them labels May 31, 2024
@aurexav
Copy link
Author

aurexav commented May 31, 2024

Hmm, I'm not too familiar with the accessibility frameworks, but if you have e.g. a NSView, I believe you can just import NSObjectNSAccessibility, and then you should be able to call accessibilityFocusedUIElement?

unsafe {
	let w = NSWorkspace::sharedWorkspace();
	let a = w.frontmostApplication().unwrap();
	dbg!(&a);
	let e = a.accessibilityFocusedUIElement();
	dbg!(e);
}

I'll get fatal runtime error: Rust cannot catch foreign exceptions if I call accessibilityFocusedUIElement.

In any case, I can recommend the AccessKit project, they abstract a lot of this for you, and their source code probably contain similar things as what you're trying to do.

Thanks, I'll take a look!

@madsmtm
Copy link
Owner

madsmtm commented Jun 1, 2024

I'll get fatal runtime error: Rust cannot catch foreign exceptions

Try running with objc2's catch-all feature - then you will see that the exception is:

uncaught exception <NSException: 0x128811df0> 'NSInvalidArgumentException' reason:-[NSRunningApplication accessibilityFocusedUIElement]: unrecognized selector sent to instance 0x128810c00

(If debug assertions are enabled, then objc2 should also have picked it up as invalid message send to -[NSRunningApplication accessibilityFocusedUIElement]: method not found).

I'm not sure, but I'm beginning to suspect that accessibilityFocusedUIElement is perhaps something meant for you to override, not call?

@aurexav
Copy link
Author

aurexav commented Jun 2, 2024

I finally resolved it using https://github.com/eiz/accessibility. Thanks.

@aurexav aurexav closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Affects the framework crates and the translator for them question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants