CGEventPostToPSN()的替代方案,用于在沙盒环境中激活其他应用程序的菜单项? [英] Alternatives for CGEventPostToPSN() for activating an other app's menu item in a sandboxed environment?

查看:205
本文介绍了CGEventPostToPSN()的替代方案,用于在沙盒环境中激活其他应用程序的菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个应用程序,需要从我的应用程序中激活另一个应用程序的菜单项(例如Print cmd + p).现在,我正在使用CGEventPostToPSN()来完成这项工作,并且工作正常,但是当我激活沙箱时,它将停止工作.

I have this app where I need to activate an other app's menu item (like Print cmd+p) from within my app. Right now I'm using CGEventPostToPSN() to do the job and it works fine, but when I activate sandboxing, it stops working.

CGEventPostToPSN(&psn, keyDownEvent);
CFRelease(keyDownEvent);
CGEventPostToPSN(&psn, keyUpEvent);
CFRelease(keyUpEvent);

我现在的问题是,当我需要启用沙箱功能时该怎么办?我听说了很多有关Accessibility API的信息,但无法找到如何激活其他应用程序的菜单项的方法.感谢您对此问题的回答.

My question now is what can I do when I need to enable sandboxing? I heard a lot about the Accessibility API but I was unable to find out how I can activate an other app's menu item. I'm thankful for any answer on this problem.

Fabian

推荐答案

对于这个问题,我仍然没有最终答案,但是似乎可以使用@nielsbot建议的Accessibility API.

I still don't have a final answer to this question, but it seems to be possible with the Accessibility API as suggested by @nielsbot.

有一些很有前途的功能,例如AXUIElementPostKeyboardEvent()AXUIElementPerformAction().问题:Apple的沙盒指南禁止使用Accessibility API控制另一个应用程序.

There are some promising functions like AXUIElementPostKeyboardEvent() and AXUIElementPerformAction(). Problem: Using the Accessibility API to control another app is prohibited in Apple's Sandbox Guideline.

注意:如本文档所述,您可以并且应该使用App Sandbox启用您的应用程序的可访问性.但是,您不能沙盒化辅助应用程序(例如屏幕阅读器),也不能沙盒化控制另一个应用程序的应用程序.

Note: With App Sandbox, you can and should enable your app for accessibility, as described in this document. However, you cannot sandbox an assistive app such as a screen reader, and you cannot sandbox an app that controls another app.

如果您遇到了这个问题,并且和我有同样的问题,我担心您不走运.重新考虑是否确实需要控制另一个应用程序,如果这样,可能无法在Mac App Store上分发您的应用程序.

If you came across this question and have the same problem as me, I fear you're out of luck. Reconsider if you really have to control another app and if so, you might not be able to distribute your app on the Mac App Store, sorry.

Fabian

这篇关于CGEventPostToPSN()的替代方案,用于在沙盒环境中激活其他应用程序的菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆