Created
March 28, 2017 16:38
-
-
Save BenAtWide/3ba468ef4f7eb7f7af44e46fea081e2b to your computer and use it in GitHub Desktop.
Dr Drang's Python -> AppleScript tool, as featured here http://www.leancrew.com/all-this/2013/03/combining-python-and-applescript/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
def asrun(ascript): | |
"Run the given AppleScript and return the standard output and error." | |
osa = subprocess.Popen(['osascript', '-'], | |
stdin=subprocess.PIPE, | |
stdout=subprocess.PIPE) | |
return osa.communicate(ascript)[0] | |
def asquote(astr): | |
"Return the AppleScript equivalent of the given string." | |
astr = astr.replace('"', '" & quote & "') | |
return '"{}"'.format(astr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment