project colordrop
Step 3: Color Detection
System Text-to-Speech Ready
Slide: 0:00 / 0:00
Slide 1 of 0Interactive Deck
Full Lesson Reference
Pick colors from anywhere on the screen.
Where We Are
You have a popover with placeholder content. Now we make it actually detect colors.
Add Color Picking
This is the core functionality:
terminal
When the popover opens, detect the color under the cursor and display it.
- Update the color preview square with the actual color
- Show the real hex value
- Show the real RGB values
- Show the real HSL values
The color should update when the popover opens.Let Claude implement this. It will likely need to:
- Request screen recording permission (macOS security requirement)
- Use macOS APIs to sample screen color
- Convert between color formats
Handle Permissions
macOS requires permission to read screen colors. When you first run:
- You'll likely see a permission prompt
- Grant "Screen Recording" permission in System Settings
- You may need to restart the app
If Claude's implementation doesn't handle permissions smoothly:
terminal
Add proper permission handling for screen capture.
If we don't have permission, show a message explaining what to do.Test It
- Move your cursor over something colorful
- Click the menu bar icon
- The popover should show that color
Try different colors:
- A blue icon
- White background
- Your desktop picture
Does it detect the correct color?
Common Issues
Wrong color / always white
terminal
The color detection is showing the wrong color.
It seems to be picking up [what it shows] instead of what's under the cursor.Permission denied
terminal
I'm getting a permission error when trying to capture screen color.
How do I request the right permissions?App doesn't update
terminal
The color doesn't update when I open the popover over different colors.
It stays the same every time.Refine the Display
Once color picking works, refine how values are displayed:
terminal
Format the values nicely:
- Hex should be uppercase with a # symbol (#FF5733)
- RGB should be formatted as "RGB(255, 87, 51)"
- HSL should be formatted as "HSL(14°, 100%, 60%)"Checkpoint
By now you should have:
- Color detection working
- Real colors showing in the preview
- Hex, RGB, HSL values displaying correctly
- Proper formatting
Stuck?
Color detection is the trickiest part. If it's not working:
- Check permissions first — System Settings → Privacy & Security → Screen Recording. Your app needs to be listed and enabled.
- Restart the app — Permission changes often require a restart
- Compare to reference — Look at
reference/ColorDrop/Sources/ColorDrop/ColorManager.swiftfor a working implementation - Ask Claude to debug — "Color detection isn't working. Here's my ColorManager code: [paste]. What might be wrong?"
See Getting Unstuck for more debugging strategies.
What You Learned
- How to work with system permissions
- Claude can handle complex APIs (screen capture, color conversion)
- Describing the format you want for data display
Exercises
- Run the "Add Color Picking" prompt, then grant Screen Recording permission and restart the app so detection actually works.
- Test detection over at least three surfaces (a colored icon, a white background, your desktop picture) and confirm each reads correctly.
- Apply the "Refine the Display" prompt and verify the hex is uppercase with
#, RGB readsRGB(255, 87, 51), and HSL readsHSL(14°, 100%, 60%).