-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardize macos window lib with other OS window libs
- Loading branch information
Showing
2 changed files
with
14 additions
and
14 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
from typing import Dict, Optional | ||
from AppKit import NSWorkspace | ||
from AppKit import NSWorkspace, NSRunningApplication | ||
from Quartz import ( | ||
CGWindowListCopyWindowInfo, | ||
kCGWindowListOptionOnScreenOnly, | ||
kCGNullWindowID | ||
) | ||
|
||
def getInfo() -> Optional[Dict[str, str]]: | ||
app = NSWorkspace.sharedWorkspace().frontmostApplication() | ||
if app: | ||
app_name = app.localizedName() | ||
title = getTitle(app.processIdentifier()) | ||
def get_current_app() -> Optional[NSRunningApplication]: | ||
return NSWorkspace.sharedWorkspace().frontmostApplication() | ||
|
||
print("appname: " + app_name + ", title: "+ title) | ||
return {"appname": app_name, "title": title} | ||
|
||
else: | ||
return None | ||
def get_app_name(app: NSRunningApplication) -> str: | ||
return app.localizedName() | ||
|
||
def getTitle(pid: int) -> str: | ||
|
||
def get_app_title(app: NSRunningApplication) -> str: | ||
pid = app.processIdentifier() | ||
options = kCGWindowListOptionOnScreenOnly | ||
windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID) | ||
|
||
for window in windowList: | ||
lookupPid = window['kCGWindowOwnerPID'] | ||
if (pid == lookupPid): | ||
return str(window.get('kCGWindowName', 'Non-detected window title')) | ||
if (lookupPid == pid): | ||
return window.get('kCGWindowName', 'Non-detected window title') | ||
return "" | ||
|