Last active
May 1, 2023 16:12
-
-
Save MoutPessemier/acddad7e8930d4a13996f1d243746e9b to your computer and use it in GitHub Desktop.
A while back my macbook always lost focus to a background process and I wanted to figure out what was drawing it's attention. That's why I created this small piece of code that you run in the background until your focus switches and it prints out what is currently in focus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
from AppKit import NSWorkspace | |
import time | |
from datetime import datetime | |
workspace = NSWorkspace.sharedWorkspace() | |
active_app = workspace.activeApplication()['NSApplicationName'] | |
print('Active focus:' + active_app) | |
while True: | |
time.sleep(1) | |
prev_app = active_app | |
active_app = workspace.activeApplication()['NSApplicationName'] | |
if prev_app != active_app: | |
now = datetime.now() | |
current_time = now.strftime("%H:%M:%S") | |
print(current_time + ' Focus changed to: ' + active_app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment