Skip to content

Instantly share code, notes, and snippets.

@munro
Created January 29, 2019 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munro/563c87e6c01df6e816bf3e27e6b5b025 to your computer and use it in GitHub Desktop.
Save munro/563c87e6c01df6e816bf3e27e6b5b025 to your computer and use it in GitHub Desktop.
macos_get_focused_application
from textwrap import dedent
import subprocess
def macos_get_focused_application():
return subprocess.check_output(['osascript'], input=dedent('''
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
''').strip().encode('utf-8')).strip().decode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment