How do I embed an AppleScript in a Python script?

后端 未结 8 752
灰色年华
灰色年华 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:35

    You can use os.system:

    import os
    os.system('''
        osascript -e 
         '[{YOUR SCRIPT}]'
         '[{GOES HERE}]'
        ''')
    

    or, as suggested by Alex Martelli you can use a variable:

    import os
    script = '''
        [{YOUR SCRIPT}]
        [{GOES HERE}]
    '''
    os.system('osascript -e ' + script)
    

提交回复
热议问题