简体   繁体   English

Cocoa:在第三方应用程序中获取和更改文本和选择(不模拟按键或使用辅助功能 API)

[英]Cocoa: get and change text and selection in third-party apps (without simulating key presses nor using accessibility API)

I'm writing a Mac utility app in which I would like to manipulate text and selection in third-party apps.我正在编写一个 Mac 实用程序应用程序,我想在其中操作第三方应用程序中的文本和选择。 I found two methods for doing so:我找到了两种方法:

However, they both have major drawbacks and I'm wondering if there are any other methods I could explore?但是,它们都有很大的缺点,我想知道是否还有其他方法可以探索?

This is precisely what services are for – see Services Implementation Guide .这正是服务的用途——请参阅服务实施指南 In a nutshell, you make an app and register it as a service provider.简而言之,您制作一个应用程序并将其注册为服务提供者。 You advertise your service using Info.plist where you specify NSStringPboardType as both the sender and return type.您可以使用Info.plist宣传您的服务,其中您将NSStringPboardType指定为发送者和返回类型。 The user will then be able to right-click on a text selection in any app and choose your service from the popup menu.然后,用户将能够右键单击任何应用程序中的文本选择,并从弹出菜单中选择您的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM