Comment 1 for bug 1556195

Revision history for this message
Krzysztof Guć (krzysiek-q) wrote :

Hi

It is problem in new El-Captain version.

Sikuli run Application using osascript:
osascript -e 'tell app "Application" to activate'

It working from terminal, but not from python subprocess

cmd=['osascript','-e','tell app "Firefox" to activate']
subprocess.Popen([cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()

It is becouse it is running not as logged user, and don't have acces to GUI.
It can be fixed adding "sudo"

cmd=['sudo','-u','LoggedUserName','osascript','-e','tell app "Firefox" to activate']
subprocess.Popen([cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()

In next step You can make switchApp
myApp=switchApp("Firefox")

args=['sudo','-u',user,'osascript','-e','tell app "Firefox"\n activate\n end tell']

It is problem with the user who run firefox it is not You, and he don't access to gui components.
You must add "sudo"

user='YourName'
args=['sudo','-u',user,'osascript','-e','tell app "Firefox"\n activate\n end tell']
subprocess.Popen(args,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()

wait(2)
myApp=switchApp("Firefox")