How do I embed an AppleScript in a Python script?

后端 未结 8 761
灰色年华
灰色年华 2020-12-25 09:13

I am trying to embed an AppleScript in a Python script. I don\'t want to have to save the AppleScript as a file and then load it in my Python script. Is there a way to enter

8条回答
  •  感动是毒
    2020-12-25 09:23

    In python 3 it would be slightly different:

    script = 'tell "some application" to do something'
    p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
    stdout, stderr = p.communicate(script)
    

    Popen now expects a byte-like object, to pass a string, the universal_newlines=True parameter is needed.

提交回复
热议问题