![]() ![]() Screencapture also does another thing I was interested in: When you press ⌘-⇧-4, followed by the space bar, you can move your mouse cursor over individual windows to screenshot them exclusively, and it’ll tint it to let you know about the selection. So much goodness I’m not able to use in a Mac App Store app, just because it’s hidden away in a private API… ![]() ‘nm’ reveals the private API CGSRegisterCursorWithImages, and several more: But it only works if the app is active and its window is frontmost – something that isn’t the case with screencapture. ![]() To set the cursor, I suspect there’s some private API magic at play.Īn app can set its cursor in different ways: via cursor rectangles or directly via NSCursor. As far as I can tell, it only contains the interactive screenshot’s origin point’s x value (where on the screen the screenshot was taken). kMDItemScreenCaptureGlobalRect – Not really a rectangular value.kMDItemScreenCaptureType – the type of screenshot: “display” for a fullscreen screenshot, “window” for a window-selected screenshot and “selection” for an interactive screenshot.Only present when the file is a screenshot, so there’s no case where NO would be specified – the tag would be missing instead. kMDItemIsScreenCapture – a boolean value indicating whether the image file is a screenshot (YES).But I suspect it’s a performance thing – perhaps drawing 5 individual single-colored windows was faster on Mac OS X Jaguar (and still might be on today’s macOS) than one NSView’s -drawRect: and they just kept going with it over the years.Ī friend and indie-colleague of mine, Andreas Monitzer ( on twitter) confirmed my suspicions: “Single-colored windows don’t need -drawRect:, and that’s probably just way more efficient.”Īlso interesting is that screencapture adds specific Spotlight metadata tags to the screenshot files it creates: Screencapture has existed since Mac OS X Jaguar (10.2), and there was no Core Animation framework yet, so that’s out of the running. Why would you need 5 windows to draw something you could draw in one, using Core Animation or an NSView? The selection cursor isn’t drawn in its own window, it’s an ordinary NSCursor, using private APIs to set it.These windows are present even if you’re not currently making a selection (albeit transparent), and they follow around your mouse cursor.screencapture uses 5 windows to display its selection rect: 4 for the edges and 1 for the fill.Knowing there’s basically no drawing on screen without an NSWindow, I created a small app that would filter out screencapture‘s windows during an interactive screenshot, create an image of each and write them to disk. Next, I wanted to know how screencapture draws its selection rectangle and cursor. ![]() I could not find any references as to how capturing the screen is done, but I suspect the CGDisplay* APIs are used, and ‘nm /usr/sbin/screencapture’ seems to confirm that theory: I executed ‘strings /usr/sbin/screencapture’ in Terminal thinking I could find a clue as to how capturing the screen was done, but all I could find were references to private APIs, like CGSGetScreenRectForWindow or CGSGetWindowLevel: Time was of the essence, after all, and I didn’t know how long it would take me to implement this stuff.īefore I started working on my own solution, I thought it’d be good to understand how macOS’ screencapture utility was implemented. Now, when I say “reimplement”, I mean I looked at the features I needed in ScreenFloat and implemented them, leaving those I didn’t need aside (fullscreen screenshots, screenshot sounds or capturing windows’ shadows, to name a few). I’d have to write my own solution for creating screenshots, basically reimplementing macOS’ screencapture command line utilityĪt the time, I didn’t know Apple would provide a new sandbox entitlement, so for me, the only choice was to take a couple of days and reimplement macOS’ screencapture‘s functionality.Apple fixes it for me in a new beta of macOS Sierra (which, as I now know, is what happened in the form of a new sandbox entitlement), or.I like to be prepared for worst-case-scenarios.Īnd when I found out my Mac app ScreenFloat didn’t work anymore on Apple’s upcoming macOS Sierra because of a new sandbox restriction (you can read the backstory here), I knew fixing it could have gone one of two ways: ![]()
0 Comments
Leave a Reply. |