Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screencapture over cron shown background instead window content

On macOs Catalina have problems with making screenshots over cron. When manually run do_screenshot.sh script then all fine. But when it run auto over cron - probs, only menu correct, instead window content shown macOs background(see pic)

do_screenshot.sh:

#!/bin/bash

DATEFULL=`date '+%Y%m%d%H%M%S'`
FILENAME="/Users/yak/Documents/screenshots/"$DATEFULL.png
/usr/sbin/screencapture -x $FILENAME

enter image description here

like image 696
Aleksandr Yakushev Avatar asked Dec 08 '19 20:12

Aleksandr Yakushev


1 Answers

Ran into this problem after the update too. Spent hours learning the details, here is the why and how. Credit goes to big-circle. The original question and answer here.

The problem is the cron doesn't have screen access.

Here's the solution

  1. close SIP (System Integrity Protection).

Make sure your SIP is disabled. To check if SIP is disabled. To to terminal and type csrutil status. It should say SIP status: enabled/disabled. To disable it:

Powerdown Mac, start up again and hold down cmd+r until OS X Utilities window shows up. Open terminal type csrutil disable. Restart again, boot into normal mac os.

  1. grant write permission to TCC

sudo chmod 664 /Library/Application\ Support/com.apple.TCC

  1. grant screencapure privilege to cron and screencapture

    a) CRON:

       `sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'insert into access values ("kTCCServiceScreenCapture", "/usr/sbin/cron", 1, 1, 1, "", "", "", "UNUSED", "", 0,"")'`
    

    b) screencapture:

       Pre Big Sur:
    `sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'insert into access values ("kTCCServiceScreenCapture", "/usr/sbin/screencapture", 1, 1, 1, "", "", "", "UNUSED", "", 0,"")'`
    

    --------------------------------------------------------------------------

       Big Sur and later:
    `sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'insert into access values ("kTCCServiceScreenCapture", "/usr/sbin/screencapture", 1,2,4,1, "", "", "", "UNUSED", "", 0,"")'`
    
  2. It's probably a good idea to turn SIP back on at this stage. To enable it, follow step 1, and instead of csrutil disable just type csrutil enable.

Edit @ 2021-12-09T11:58:00+1000: Added in commands for Big Sur and later per comment from Silvan Mühlemann

like image 132
A Web-Developer Avatar answered Sep 18 '22 01:09

A Web-Developer