A macOS utility that captures a selected area of your screen and extracts text from it using OCR (Optical Character Recognition). The extracted text is automatically copied to your clipboard for easy use.
- Screen Area Selection: Interactive screen capture using macOS's built-in screencapture tool
- OCR Processing: Uses Apple's Vision framework for accurate text recognition
- Clipboard Integration: Automatically copies recognized text to clipboard
- Fast Processing: Optimized for quick text extraction
- Error Handling: Comprehensive error messages and validation
- macOS 10.15 (Catalina) or newer - Required for Vision framework OCR
- Xcode Command Line Tools - For compiling Swift code
- Screen Recording Permission - macOS will prompt for this on first run
-
Clone or download the project:
git clone <repository-url> cd screen2text
-
Compile the Swift file:
swiftc MyApp.swift -o screen2text
-
Run the application:
./screen2text
-
Make the script executable:
chmod +x MyApp.swift
-
Run directly (requires Swift to be in PATH):
swift MyApp.swift
- Run the application using one of the methods above
- Select screen area: A crosshair cursor will appear - click and drag to select the area containing text
- Wait for processing: The app will process the image and extract text
- Text is copied: The recognized text is automatically copied to your clipboard
- View results: The extracted text is also displayed in the terminal
✅ OCR result copied to clipboard:
Hello World!
This is some sample text
that was captured from the screen.
- Screen Recording: If prompted, grant screen recording permission in System Preferences > Security & Privacy > Privacy > Screen Recording
- Accessibility: May need accessibility permissions for clipboard access
- Xcode Command Line Tools: Install with
xcode-select --install - Swift version: Ensure you have a recent version of Swift installed
- No text found: Ensure the selected area contains clear, readable text
- Poor recognition: Try selecting a larger area or ensure text has good contrast
- Language support: Currently optimized for English (en-US)
- Screen Capture: Uses macOS
screencapturecommand-line tool - OCR Engine: Apple's Vision framework with VNRecognizeTextRequest
- Image Processing: Converts NSImage to CGImage for Vision processing
- Threading: Uses DispatchSemaphore for synchronous OCR processing
- Error Handling: Comprehensive validation and error reporting
Edit line 58 in MyApp.swift:
request.recognitionLanguages = ["pt-BR"] // For PortugueseEdit line 56 in MyApp.swift:
request.recognitionLevel = .accurate // For better accuracy (slower)This project is open source. Feel free to modify and distribute as needed.
Contributions are welcome! Please feel free to submit issues and pull requests.