How do I communicate between python and a mac application?

后端 未结 5 1779
慢半拍i
慢半拍i 2021-01-20 20:34

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

I developed an app that was originally developed as a Mac applicatio

相关标签:
5条回答
  • 2021-01-20 21:14

    On osx, many native applications support AppleScript (aka OSA) as their native scripting API. Thus your question becomes one of interacting between Python and Applescript (and figuring out how to talk to your target application in AppleScript in the first place).

    There is some OSA support in the Python standard library and a third-party module py-applescript you might want to look at.

    0 讨论(0)
  • 2021-01-20 21:17

    In my eyes the simplest way to establish communication between two applications is the client-server protocol XMLRPC. Both Cocoa and Python do support it.

    The Python part is fairly simple:

    import xmlrpc.client
    rpcProxy = xmlrpc.client.ServerProxy(URL_OF_SERVER)
    rpcProxy.SendKeyToApp(pid,key)
    

    As for the Cocoa-part, I don't know, but it seems to be possible: XML-RPC Server in Cocoa or Best way to use XML-RPC in Cocoa application?

    0 讨论(0)
  • 2021-01-20 21:23

    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.

    For the ones interested, it's called atomac.

    0 讨论(0)
  • 2021-01-20 21:30

    PyObjC is perhaps what you're looking for:

    PyObjC (pronounced pie-obz-see) is the key piece which makes it possible to write Cocoa applications in Python. It enables Python objects to message Objective-C objects as if they're fellow Python objects, and likewise facilitates Objective-C objects to message Python objects as brethren.

    You could write a bridge between your python app and your cocoa app using PyObjC.

    0 讨论(0)
  • 2021-01-20 21:39

    There are many ways to synchronize/communicate the data between two applications, but let me explain the simplest :

    RESTful Serialization:
    Serialize the objects into XML/JSON or any other custom format both app frameworks can parse. eg. http://docs.python.org/library/json.html
    If both apps are on the same server/machine I'm expecting all you have to do is to encode/store the data into the same file(s) and read/parse the data from respective file(s) in other application.

    Otherwise you may need to create a web service for accessing the data file.

    Let me know in comments if you have further queries.

    0 讨论(0)
提交回复
热议问题