script = """tell application "System Events"
    activate
    display dialog "Hello Cocoa!" with title "Sample Cocoa Dialog" default button 2
end tell
"""
proc = subprocess.Popen(['osascript', '-'], stdin=subprocess.PIPE, stdout=
    subprocess.PIPE)
stdout_output = proc.communicate(script)[0]
print(stdout_output, type(proc))
How to run an AppleScript from within a Python script?