I want to call this terminal command on macOS in python lsappinfo info -only name
. It returns the name of the current foreground application.lsappinfo front
Here is how I understand the command:
lsappinfo
return information about running appsinfo
allows to select specific data
select the foreground processlsappinfo front
name
select the name of the process only
And here is my current code:
import subprocess
sub = subprocess.Popen(['lsappinfo', 'info', '-only', 'name', '`lsappinfo front`'])
out, err = sub.communicate()
print(err)
print(out)
But I get:
>>> None
>>> None
The expected output of the command is
"LSDisplayName"="AppName"
I succeed using os.system()
but I want to achieve it with subprocess
since it's the recommended way and I want to store the output. Does someone know how to do it?