Skip to content

Instantly share code, notes, and snippets.

@krubenok
Last active September 30, 2024 12:22
Show Gist options
  • Save krubenok/de77672b8ce7d86ffbcd80f9a9cfd9bd to your computer and use it in GitHub Desktop.
Save krubenok/de77672b8ce7d86ffbcd80f9a9cfd9bd to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
PLIST=~/Library/Group\ Containers/group.com.apple.replayd/ScreenCaptureApprovals.plist
CURRENT_DATE=$(date +%s)
ONE_YEAR_FROM_NOW=$(date -v+1y +%s)
if [ -f "$PLIST" ]; then
# Contents of the plist file look like this:
# Dict { /Applications/1Password.app/Contents/MacOS/1Password = Sat Sep 21 11:59:57 PST 2024 /Applications/Microsoft Teams.app/Contents/MacOS/MSTeams = Tue Sep 21 05:40:36 PST 3024 /Applications/CleanShot X.app/Contents/MacOS/CleanShot X = Tue Sep 21 05:40:36 PST 3024 /Applications/Ice.app/Contents/MacOS/Ice = Sat Sep 21 05:40:36 PST 2024 /Applications/Shottr.app/Contents/MacOS/CleanShot X = Tue Sep 21 05:40:36 PST 3024 }
# Remove the 'Dict {' and '}' from the output
PLIST_CONTENT=$(echo "$PLIST_CONTENT" | sed 's/Dict { //; s/ }$//')
# Split PLIST_CONTENT into an array based on new lines
IFS=$'\n' read -rd '' -a entries <<<"$PLIST_CONTENT"
for ((i=1; i<${#entries[@]}-1; i++)); do
APP_PATH=$(echo "${entries[i]}" | awk -F ' = ' '{print $1}' | sed 's/^ *//')
APP_DATE=$(echo "${entries[i]}" | awk -F ' = ' '{print $2}')
APP_TIMESTAMP=$(date -j -f "%a %b %d %T %Z %Y" "$APP_DATE" +%s)
if [ "$APP_TIMESTAMP" -lt "$ONE_YEAR_FROM_NOW" ]; then
NEW_DATE=$(date -j -f "%s" "$ONE_YEAR_FROM_NOW" "%a %b %d %T %Z %Y")
echo "App: $APP_PATH"
echo "Current Date: $APP_DATE"
read -p "Would you like to set the date for $APP_PATH screen recording permissions prompt to one year from today? (y/n): " response
if [[ "$response" == "y" ]]; then
/usr/libexec/PlistBuddy -c "Set :$APP_PATH '$NEW_DATE'" "$PLIST"
echo "Date for $APP_PATH updated to $NEW_DATE"
else
echo "Date for $APP_PATH not changed."
fi
fi
done
#
else
echo "ScreenCaptureApprovals.plist not found."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment