Data is a pretty amorphous thing, but it sounds like you're talking about image data.
Apple's AppKit framework, after the tools in KM itself of course, is where I would look for native tools for messing with image data.
Here's a eureka moment worth looking at:
It shows how to convert the base64string data in an <"image"> key in an action dictionary to NSImage a native object in the Cocoa AppKit framework. Lots of other conversions are also possible with NSImage.
Stuff I am not particularly familiar with but could look up.
Of course, KM has a ton of tools for manipulating images.
https://wiki.keyboardmaestro.com/Home_Page?do=search&id=User_Manual&q=image
As for getting info and data while an app is not front, absolutely. If the developer makes it available via AppleScript it's possible. Excel can do it all it the background.
Because the KM Editor's AppleScript makes the xml of an action available when the app is not front, accessing this data can happen when the app is not front.
The same goes for Engine's getmacros, gethotkeys plist data.
Preview is an app that doesn't require that it is front to get the path of a window's document's path.
tell application id "com.apple.Preview"
path of document 1 of window 1
end tell
Not raw in-memory data, but you get the drift.
As for XQuartz, after a brief web search, I'm still not seeing a relationship with image data.
If what you're after is PDF images, you might be thinking of Quartz, the native Apple framework to "Allow users to browse, edit, and save images, using slideshows and Core Image filters."
I know of it and that people have, I think, used AppleScriptObjC to manipulate Pdfs.
I have no idea if image extraction can be done with it.
You'd start by declaring this at the top of a script.
use framework "Quartz"
And that is as far as my Quartz scripting understanding goes.![]()