def is_runnning(app):
    count = int(subprocess.check_output(['osascript', '-e',
        'tell application "System Events"', '-e', 
        'count (every process whose name is "' + app + '")', '-e',
        'end tell']).strip())
return count > 0
How to use python to detect if an application is running and if a message box is displayed under MAC OS