Automate screenshot of a specific window

I'm trying to create a workflow in Mac Shortcuts.app (or Automator if preferable) to take a Screenshot of a specific window.


I'm confused by Shortcuts.app, which seems to offer various possibilities, but I can't get any of them to work, except Full Screen and/or Interactive (same as Cmd-Shift-4 ... spacebar)


The alternative of using; Select Magic Variable, doesn't appear to accept any input. I have used Find Windows to select the window I want, which correctly shows the window in the Shortcut.app's window, when I run the Shortcut, but it isn't passed as a Magic Variable despite it being accepted as one. No matter what I try, it always takes a screenshot of the Full Screen.


I'm wondering if these are simply buggy 'shortcuts' originally developed for iOS and poorly implemented into Monterey??


Either way... can anyone suggest how I could automate taking a screenshot of a specific window?


This is the simplest vs of what I'm getting. The window I want is the small one top-left. Full-Screen is what is returned.


MacBook Pro Retina

Posted on Feb 21, 2022 4:58 AM

Reply
4 replies

Feb 22, 2022 5:34 AM in response to gee-eff-ess

I believe that Shortcuts was originally written for iOS by a 3rd Party and Apple acquired the company and they have been enhancing the product. Building it into iOS itself. It was ported over to Monterey but it may not yet be fully fleshed out for Monterey and therefore lacks the ability you seek. There are no "windows" on iOS only the active screen.


I have found other potential solutions that do not require "interactive', where the user selects the window. Utilizing AppleScript and the built-in command line "screencapture" tool using a window id as well as workarounds to find the window id for Apps that do not support AppleScript. The open source "screenshot" tool does most all that work for you.


❯ sw_vers
ProductName:	macOS
ProductVersion:	12.2.1
BuildVersion:	21D62

❯ /usr/bin/python --version
Python 2.7.18

❯ /usr/bin/python3 --version
Python 3.8.9

❯ /usr/bin/pip3 --version
pip 20.2.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)


The tool states Python 3.6.x is required so the built-in developer tools should suffice.


If you need a newer Python then you should install the Homebrew package manager (httphttps://brew.sh) and use it to install the newer Python3 version.


[Apple Silicon Macs, Homebrew installs into /opt/homebrew, while Intel Macs use /usr/local/Cellar)


❯ which python3
/opt/homebrew/bin/python3

❯ python3 --version
Python 3.9.10 



Feb 22, 2022 1:52 AM in response to James Brickley

Thanks James.


This is an interesting approach. It says you have to install Python 3.x but a google suggested it is already installed in Monterey? (I'd prefer to not have to install anything).


Do you agree that the Shortcuts app is misleading/broken in this respect? Seems bizarre that it suggests you can choose a window and offers the setup controls to do so, but it doesn't work and if it is actually just legacy code from the iOS version ... there aren't any windows in iOS, so how would that work?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automate screenshot of a specific window

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.