I just want to know if this can be done in one command without any interactions in macOS. There's an interactive way to do this (I first switched to the user abc and then switched back so that abc had a hidden desktop):
(in sudo mode) login abc (type the password) screencapture <png-file-name> In my test, this would take a screenshot of abc's hidden desktop and save it to the file. But the weird thing is that when I use -f option (only applicable in sudo mode) to eliminate the need of typing password, the screenshot becomes the current user's desktop, not abc's desktop:
(in sudo mode) login -f abc /usr/sbin/screencapture <png-file-name> OR login -f abc bash -c "/usr/sbin/screencapture <png-file-name>" Both don't work as expected.
su or sudo also can't meet my requirements, because they also take the screenshots of current user's desktop.
You may wonder why I want that. In fact I don't want the screenshots, I want security. I want to make the shell of this another user completely isolated from the current user, so that any malicious code running in this shell will not be able to take screenshot of the current user.
screencapturegrabs the currently visible screen, independent of the user logged in through Terminal. Which problem are you trying to solve here? Can you describe it without making assumptions about the solution yet?screencapturecaptures the other user's screen when inlogin, but captures the current visible screen insu -u,sudo -u, orlogin -f. But first you need to use UI to log in to that user then switch back (not quit) to make his desktop hidden. I've modified the description to clarify.