Skip to content

Conversation

@mercersoft
Copy link
Collaborator

This PR adds the ability for cycod to take screenshots, both on Window and on MacOS.

On Windows it will take a screenshot of the default screen.

On MacOS it can take a screenshot of any window that can be identified by name or process id.

robch and others added 4 commits December 12, 2025 11:10
- Add OSX and LINUX compilation symbols to cycod.csproj
- Implement native macOS screenshot capture using Core Graphics framework
- Add P/Invoke declarations for CGDisplay, CoreFoundation, and ImageIO APIs
- Update platform support checks to include macOS alongside Windows
- Update error messages and descriptions to reflect macOS support
- Maintain proper memory management with CFRelease for Core Foundation objects

The implementation uses native macOS APIs without external dependencies:
- CGDisplayCreateImage for screen capture
- CGImageDestination for PNG export
- CFURL and CFString for file path handling

Tested: Build succeeds with no errors or warnings
Features:
- ListWindows() - Enumerate all visible application windows with metadata (JSON)
- TakeScreenshotOfApp(appName) - Capture screenshots by application name
- TakeScreenshotOfWindowWithTitle(title) - Capture screenshots by window title
- TakeScreenshotOfDisplay(displayNumber) - Capture specific displays
- TakeScreenshotOfWindow(windowId) - Advanced: capture by window ID

Implementation:
- Uses hybrid approach: Core Graphics for window enumeration + screencapture CLI for capture
- No Screen Recording permissions required when run from terminal
- Case-insensitive, partial matching for app names and titles
- Returns helpful error messages when multiple windows match
- Properly guarded with #if OSX for macOS-only code

Files:
- Added: src/cycod/Helpers/WindowInfo.cs - Window metadata class
- Modified: src/cycod/Helpers/ScreenshotHelper.cs - Core screenshot and enumeration logic
- Modified: src/cycod/FunctionCallingTools/ScreenshotHelperFunctions.cs - AI tool wrappers
- Added: docs/macos-window-screenshot-feature.md - Feature documentation

Fixes:
- Fixed macOS screenshot permissions issue by using screencapture CLI instead of Core Graphics capture
- Fixed CGWindowListCopyWindowInfo import (CoreGraphics framework, not CoreFoundation)
- Fixed dictionary key names (use 'k' prefix: kCGWindowOwnerName)
@mercersoft mercersoft requested review from Copilot and robch December 22, 2025 22:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends cycod's screenshot functionality to support macOS in addition to Windows. On Windows, it captures the default screen; on macOS, it can capture specific windows identified by name or process ID, as well as entire displays.

Key Changes:

  • Added macOS screenshot support using native screencapture utility and Core Graphics APIs
  • Implemented window enumeration and targeted screenshot capture for macOS
  • Updated platform checks throughout to include OSX alongside Windows

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/cycod/cycod.csproj Added OSX and LINUX build constants for conditional compilation
src/cycod/SlashCommands/SlashScreenshotCommandHandler.cs Updated platform check to support both Windows and macOS
src/cycod/Helpers/WindowInfo.cs New data class representing macOS window metadata
src/cycod/Helpers/ScreenshotHelper.cs Core screenshot functionality with macOS window enumeration and capture methods
src/cycod/FunctionCallingTools/ScreenshotHelperFunctions.cs AI-callable wrapper functions for screenshot operations
docs/macos-window-screenshot-feature.md Documentation of the new macOS screenshot capabilities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mercersoft and others added 2 commits December 22, 2025 14:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants