Skip to content
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

Add experimental MacOS support #13

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ htmlcov/

dist/
build/
*.egg-info/
*.egg-info/
pip-wheel-metadata/

# IDE
.vscode
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name = "pypi"
"win32gui" = "*"

[dev-packages]
pylint = "*"

[requires]
python_version = "3.6"
94 changes: 91 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,23 @@ PyGetWindow has functions for obtaining ``Window`` objects from a place on the s
(142, 110)
>>> notepadWindow.close()
>>>

## MacOS
MacOS implementation is not yet feature complete and is experimental so YMMV. However, the following is possible.

>>> import pygetwindow as gw
>>> gw.getAllTitles()
['SystemUIServer AppleClockExtra', 'OneDrive Item-0', 'SystemUIServer AirPortExtra', 'MindNode Quick Entry Item-0', 'Tunnelblick Item-0', 'ClickShare Client Item-0', 'Docker Item-0', 'OneDrive Item-0', 'Alfred 3 Item-0', 'VMware Fusion Start Menu Item-0', 'SystemUIServer AppleTimeMachineExtra', 'SystemUIServer AppleVPNExtra', 'SystemUIServer AppleBluetoothExtra', 'SystemUIServer BatteryExtra', 'SystemUIServer AppleVolumeExtra', 'Spotlight Item-0', 'SystemUIServer NotificationCenter', 'Window Server Menubar', 'Dock Dock', 'Code README.md — PyGetWindow', "Safari darth-veitcher/PyGetWindow: A simple, cross-platform module for obtaining GUI information on application's windows.", 'Amazon WorkSpaces Amazon WorkSpaces', 'Slack Slack - MyCompany', 'Finder Data Driven Organisation', 'Microsoft OneNote myname @ MyCompany O365', 'Terminal public — core@asimov:~/coco-annotator — python -m http.server — 161×53', 'Terminal myname — jupyter_mac.command — -bash — 80×24']
>>> gw.getAllWindows()
[MacOSWindow(hWnd=13408), MacOSWindow(hWnd=53), MacOSWindow(hWnd=3854), MacOSWindow(hWnd=45), MacOSWindow(hWnd=103), MacOSWindow(hWnd=100), MacOSWindow(hWnd=89), MacOSWindow(hWnd=106), MacOSWindow(hWnd=3852), MacOSWindow(hWnd=87), MacOSWindow(hWnd=85), MacOSWindow(hWnd=41), MacOSWindow(hWnd=61), MacOSWindow(hWnd=37), MacOSWindow(hWnd=49), MacOSWindow(hWnd=57), MacOSWindow(hWnd=35), MacOSWindow(hWnd=24), MacOSWindow(hWnd=3), MacOSWindow(hWnd=33), MacOSWindow(hWnd=13264), MacOSWindow(hWnd=13320), MacOSWindow(hWnd=6359), MacOSWindow(hWnd=8566), MacOSWindow(hWnd=9331), MacOSWindow(hWnd=6585), MacOSWindow(hWnd=74), MacOSWindow(hWnd=77)]

As with Windows implementation, MacOS windows can be activated and minimised.

>>> safari = gw.getWindowsWithTitle('Safari')[0]
>>> safari.isActive
False
>>> safari.activate()
>>> safari.activate(); time.sleep(3); safari.isActive
True
>>> safari.size
Size(width=870.0, height=560.0)
5 changes: 4 additions & 1 deletion src/pygetwindow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def pointInRect(x, y, left, top, width, height):


if sys.platform == 'darwin':
raise NotImplementedError('PyGetWindow currently does not support macOS. If you have Appkit/Cocoa knowledge, please contribute! https://github.com/asweigart/pygetwindow') # TODO - implement mac
# raise NotImplementedError('PyGetWindow currently does not support macOS. If you have Appkit/Cocoa knowledge, please contribute! https://github.com/asweigart/pygetwindow') # TODO - implement mac
from ._pygetwindow_macos import MacOSWindow, getActiveWindow, getWindowsAt, getAllTitles, activate
from ._pygetwindow_macos import _getWindowsByTitle as getWindowsWithTitle, _getAllWindows as getAllWindows
Window = MacOSWindow
elif sys.platform == 'win32':
from ._pygetwindow_win import Win32Window, getActiveWindow, getWindowsAt, getWindowsWithTitle, getAllWindows, getAllTitles
Window = Win32Window
Expand Down
Loading