如何在python和mac应用程序之间通信? [英] How do I communicate between python and a mac application?

查看:160
本文介绍了如何在python和mac应用程序之间通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个模糊的问题,但我未能正确地重新表述.所以这是一个解释.

This might be a vague question, but I failed to rephrase it properly. So here's an explanation.

我开发了一个应用程序,该应用程序最初是作为Mac应用程序开发的,同时使用Carbon/Cocoa的API来完成我的任务. (该应用程序的目标是在鼠标移动/其他击键之后向应用程序发送击键".为此,我使用了Accessibility API).

I developed an app that was originally developed as a Mac application, using API's from both Carbon/Cocoa to achieve my task. (The goal of the application is to send 'keystrokes' to an app after mouse movements / other keystrokes. I use Accessibility API's for that).

但是现在,我想添加脚本支持,因此可能会有条件的击键.例如:按下"Y"五次后,我想按下按钮"B".

But now, I want to add scripting support, so there can be conditional keystrokes. Such as: after 5 times of pressing 'Y', I want to press the button 'B'.

在OSX内,Python应用程序不可能做这种事情,而且我找不到任何允许我执行此操作的库.所以我想我会将应用程序制作成两块.首先:我将在Cocoa/Carbon中编写一个具有以下基本功能的应用程序:SendKeyToApp(pid,key)和WaitForMovement().

Within OSX, there's no possibility for a Python app to do such a thing, and I can't find any libraries that allow me to do it. So I figured I'd make the app two-fold. First: I'll write an app in Cocoa/Carbon with the basic functions: SendKeyToApp(pid,key) and WaitForMovement().

python应用程序将使用这些方法调用与该应用程序通信.这里的问题是:我该如何在这两个应用程序之间进行通信?我将使用HTTP服务器,套接字服务器还是某种subprocess.Popen()hacks.坦白地说,我不知道.

The python app will communicate with that app, using those method calls. The question here is: how do I communicate between those two apps? Will I use a HTTP Server, a Socket Server, some kind of subprocess.Popen() hacks. I frankly have no idea.

有人有什么想法可以完成这样的任务吗?

Does anyone have any ideas to achieve such a task?

推荐答案

更简单.我从Python内部使用了Accessibility API,这一切使我可以轻松实现此目的,而根本不需要任何可可/碳素.

Easier. I went to use Accessibility API's from within Python, and it all allowed me to easily do this without any Cocoa / Carbon at all.

对于感兴趣的人,它称为 atomac.

For the ones interested, it's called atomac.

这篇关于如何在python和mac应用程序之间通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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