I've got a problem when I try to import NSWorkspace an error appears:
No name 'NSWorkspace' in module 'AppKit'
Here is my code :
from AppKit import NSWorkspace
import time
activeAppName = ""
while True:
NewactiveAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']
if activeAppName != NewactiveAppName:
activeAppName = NewactiveAppName
print (activeAppName)
time.sleep(10)
Python v3 does not import module AppKit with capital letters but requires lower ones:
import appkit
So, in my case, the original way works with only Python v2.
When I tried Python 3, it produced the following error:
When I use python 2.7 — it works fine:
NO ERROR.
Definitely, I have tried the recommended
pip3 install AppKit PyObjC
to no avail.There is a recommendation that I didn't try. So, I stick to use Python2 with the following script:
————
UPDATE:
I have manually updated my AppKit library for python 3 and now use it in Python3-based script. https://github.com/TinKurbatoff/appkit