Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use python to detect if an application is running and if a message box is displayed under MAC OS

I am trying to write unit test for an application on Mac OS using python. There is one problem I encounter and have no idea how to do it. I want the testing program to check if the application is running by checking process and I also want to check if a message box is displayed. In addition, I hope testing program can automatically click button on message box. Could anyone give me some suggestions?

like image 493
Robin W. Avatar asked Oct 22 '22 18:10

Robin W.


1 Answers

Here's one way to do it with AppleScript:

import subprocess

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

print is_runnning("iTunes")

See also this for some variations.

like image 116
Hugo Avatar answered Oct 24 '22 11:10

Hugo