I hear that more and more people work at home, and many people are worried that they are all working at home properly.
I think it's strange to be anxious in the first place, but I also wonder if some people will be in trouble if their boss becomes anxious.
So, I thought that if I could collect information on the apps I'm using in real time when using a computer, I could reduce that anxiety a little, so I considered a method.
Here, I will summarize the method of "getting and displaying the title of the active window every time the active window is changed".
For Mac, install the required library with the following command.
pip install -U PyObjC
For Windows, install the required library with the following command.
pip install -U pywin32
#!/usr/bin/env python import sys #For Mac if sys.platform == "darwin": from AppKit import NSWorkspace from Quartz import ( CGWindowListCopyWindowInfo, kCGWindowListOptionOnScreenOnly, kCGNullWindowID ) def getActiveWindowTitle(): curr_app = NSWorkspace.sharedWorkspace().frontmostApplication() curr_pid = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationProcessIdentifier'] curr_app_name = curr_app.localizedName() options = kCGWindowListOptionOnScreenOnly windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID) txt = "" for window in windowList: pid = window['kCGWindowOwnerPID'] windowNumber = window['kCGWindowNumber'] ownerName = window['kCGWindowOwnerName'] geometry = window['kCGWindowBounds'] windowTitle = window.get('kCGWindowName', u'Unknown') if curr_pid == pid: activeWindowTitle = ownerName + " - " + windowTitle return activeWindowTitle #For windows elif sys.platform == "win32": import win32gui def getActiveWindowTitle(): activeWindowTitle = win32gui.GetWindowText(win32gui.GetForegroundWindow()); return activeWindowTitle else: def getActiveWindowTitle(): return "" def main(): bufWindowTitle = "" try: while True: activeWindowTitle = getActiveWindowTitle() if bufWindowTitle != activeWindowTitle: print(activeWindowTitle) bufWindowTitle = activeWindowTitle except KeyboardInterrupt: sys.exit(0) if __name__ == '__main__': main()
After creating it, execute it with the following command.
You should see the application name each time you switch the active window.
If you send this to the specified server, you will know that you are working properly, and it is okay to be told "Prove!"! !! ...All right! ......I think it's okay.