Fix macOS SSH desktop capture with Quartz - #1
Merged
Conversation
Pillow ImageGrab on Darwin shells out to screencapture, which fails from OpenSSH even when Screen Recording is already granted to Python. Capture through CGDisplayCreateImage instead, and keep the frame in CGDisplayPixelsWide/High space so mouse coordinates still match Quartz input. PyObjC 12 also stopped exporting AXIsProcessTrusted on the Quartz module, so Accessibility checks fall back to ApplicationServices.
Owner
|
lgtm 👍🏾 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
SSHDESK on macOS can be fully installed (venv, forced command, sudoers, Screen Recording, Accessibility) and still fail the moment a client connects:
That is not a missing TCC prompt and not a broken OpenSSH config.
sshdesk-servernever gets a frame.Root cause:
NativeCapturecalls PillowImageGrab.grab(). On Darwin, current Pillow does not use CoreGraphics. It shells out to/usr/sbin/screencapture. That CLI has failed from SSH sessions for years, even when the Python process already has Screen Recording. On a headless Mac whose only display is a Screen Sharing virtual display, it also fails underlaunchctl asuser.The docs said NativeCapture used “Pillow’s CoreGraphics path.” The code did not.
Second bug, same session: if capture is fixed first, PyObjC 12 then crashes input with
AttributeError: AXIsProcessTrusted. That symbol is no longer exported on theQuartzmodule, soMacOSInputdies before any click/key is injected.The fix
CGDisplayCreateImage(already asshdesk[macos]dependency) inside the TCC-permitted Python process. Do not callscreencapture.CGDisplayPixelsWide×CGDisplayPixelsHighso mouse coordinates matchMacOSInput.ImageGrab.Quartz.AXIsProcessTrustedas optional; fall back to the ApplicationServices C API.ImageGrabon Darwin, and the Accessibility fallback.Verified
Mac Studio, Darwin 25 / macOS 26, Apple M3 Ultra, headless Screen Sharing virtual display, SSHDESK 0.4.5:
screencapture -x→could not create image from display(exit 1)CGDisplayCreateImage→ real 2642×1640 framesshdesk-server --check→1321x820 NativeCapture capture; input=enabledsshdesk-agent screenshotreturned the live Finder desktopssh -tset the title toSSHDESK - Martins-Mac-Studio.localand started drawingTest plan
python3 -m venv .venv .venv/bin/python -m pip install -e '.[dev]' .venv/bin/python -m unittest discover -s tests -v .venv/bin/ruff check src testsOn a macOS host with Screen Recording + Accessibility granted to the venv Python: