@Sam R At this point I think you should stop for a moment and seriously consider your options.
The problems that I can see are as follows.
- Using a commandline tool to take the screenshot; to which I assume is saving to disk is wasteful and eats into the users write allowance on SSDs, not to mention you have the time involved in writing and reading.
- The built-in Apple method requires the user learns to click on select color and then the eyedropper; but the reat is handled for you and is allowed on Catalina. I’ll agree it’s pretty a pretty ugly workaround and that’s why I don’t use it myself.
- If you only need sampling from your own windows; there’s API for that, which would speed up your solution and in theory shouldn’t cross Catalina’s privacy rules.
- If you need sampling of the screen, i.e. content you don’t control, there’s API for that. You’ll need to research which API is permitted under Catalina (if any).
- If you really see absolutely no way to do this without using the commandline functions; then take a screenshot. Load it into your application and throw up a full screen window, and sample from there, you’ll have full control over your cursor (real or fake), you only deduct 1 write from the SSD allowance, and it **should** be smooth without flickering.
- Make sure you are at least testing this with Catalina; as it’s gone privacy mad, your app may not even be able to capture the screen at all. I know that some devs have had to pull their apps or functionality from the App Store because of this; although I’ll confess that I never investigated which methods are no longer allowed.
This of course is just my thoughts and possible solutions.
Thanks for your thoughtful response, Sam.
1. The command line approach saves a single file to the temporary cache folder. Each save overwrites the previous file, and the file is only about 150KB. Once the sampling is complete, the file is immediately erased. So no worries about wasted space. It does read and write to the SSD while sampling, but that theoretically only happens for a few seconds whenever the user wants that feature. I think this is fine.
2, 3, 4. I have to sample the entire screen. The app is a color picker that lets you grab a color from anywhere on the screen, including outside of the app. I can control the cursor just fine outside of my app. Everything about this approach works great. I can sample the full screen, the magnifier looks perfect, and everything behaves as intended.
5. I cannot load the screenshot into my application, because I need to provide "live" sampling. Meaning if the user hovers over a button, or the Dock, or tabs to a different window, the color picker should always pull the color of the active control or the changing screen dynamically. I can get away with this by only sampling a small section of the screen just around the cursor, and doing that repeatedly as the mouse moves until the sampling is complete. It all works very well and is incredibly fast (while also requiring almost not CPU/RAM for the app).
6. I have this running fine on Catalina and all is working well.
The only issue is, when I screenshot the area around the cursor, if the cursor is my custom magnifier, then the screenshot is basically just the magnification cursor, not the true screen underneath. Which is why I need to omit the cursor from the screenshot (without hiding it and showing it, which causes the cursor to flicker). I know there is a way to take a screenshot of the screen without the cursor, even a custom cursor, as the screen is treated as a layer. Each window is its own layer, and the cursor is its own layer. I just cannot figure out how to take a screenshot that omits the cursor when Xojo has set it to a custom cursor. It is honestly quite frustrating.