Skip to content

Instantly share code, notes, and snippets.

@BenAtWide
Created March 28, 2017 16:38
Show Gist options
  • Save BenAtWide/3ba468ef4f7eb7f7af44e46fea081e2b to your computer and use it in GitHub Desktop.
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/
#!/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