Created
February 22, 2017 09:28
-
-
Save peter-jung/c1ba664e5306fe029cf02383b4145d0a to your computer and use it in GitHub Desktop.
How to call an Applescript from Python on Mac?
This file contains 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
import subprocess, sys | |
applescript=''' | |
tell application "System Events" | |
set processName to name of processes whose frontmost is true | |
do shell script "echo " & processName | |
end tell | |
''' | |
args = [item for x in [("-e",l.strip()) for l in applescript.split('\n') if l.strip() != ''] for item in x] | |
proc = subprocess.Popen(["osascript"] + args ,stdout=subprocess.PIPE ) | |
progname = proc.stdout.read().strip() | |
sys.stdout.write(str(progname)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment