-
-
Notifications
You must be signed in to change notification settings - Fork 70
Update MacOS title logic #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ __pycache__ | |
| build | ||
| dist | ||
| *.swp | ||
| .mypy_cache | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,10 @@ | ||
| aw-watcher-window | ||
| ================= | ||
| # aw-watcher-window | ||
|
|
||
| Cross-platform window-Watcher for Linux (X11), macOS, Windows. | ||
|
|
||
| [](https://travis-ci.org/ActivityWatch/aw-watcher-window) | ||
|
|
||
| ### Note to macOS users | ||
|
|
||
| To log current window title the teminal needs access to macOS accessibility API. | ||
| To log current window title the terminal needs access to macOS accessibility API. | ||
| This can be enabled in System Preferences > Security & Privacy > Accessibility, then add the Terminal to this list. If this is not enabled the watcher can only log current application, and not window title. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,28 @@ | ||
| import subprocess | ||
| from subprocess import PIPE | ||
| import os | ||
| from typing import Optional | ||
| from AppKit import NSWorkspace | ||
| from Quartz import ( | ||
| CGWindowListCopyWindowInfo, | ||
| kCGWindowListOptionOnScreenOnly, | ||
| kCGNullWindowID | ||
| ) | ||
|
|
||
| def getInfo() -> Optional[dict]: | ||
| app_name = '' | ||
| title = '' | ||
|
|
||
| def getInfo() -> str: | ||
| cmd = ["osascript", os.path.join(os.path.dirname(os.path.realpath(__file__)), "printAppTitle.scpt")] | ||
| p = subprocess.run(cmd, stdout=PIPE) | ||
| return str(p.stdout, "utf8").strip() | ||
| app = NSWorkspace.sharedWorkspace().activeApplication() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
and is replaced by |
||
|
|
||
| if app: | ||
| pid = app['NSApplicationProcessIdentifier'] | ||
|
|
||
| def getApp(info) -> str: | ||
| return info.split('","')[0][1:] | ||
| options = kCGWindowListOptionOnScreenOnly | ||
| window_list = CGWindowListCopyWindowInfo(options, kCGNullWindowID) | ||
| for window in window_list: | ||
| if pid == window['kCGWindowOwnerPID']: | ||
| # We could use app['NSApplicationName'], but this value is more | ||
| # accurate and matches other methods (like applescript) | ||
| app_name = window['kCGWindowOwnerName'] | ||
| title = window.get('kCGWindowName', u'') | ||
| break | ||
|
|
||
|
|
||
| def getTitle(info) -> str: | ||
| return info.split('","')[1][:-1] | ||
| return {"appname": app_name, "title": title} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it ever happens that the pid isn't found in |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, the extra changes here were due to prettier, I believe. Let me know if you want them reverted. Not sure why it would remove the trailing line...