Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jonathanweinberg/ad227ef90353e363a75279ef05c89899 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanweinberg/ad227ef90353e363a75279ef05c89899 to your computer and use it in GitHub Desktop.

Revisions

  1. @timsutton timsutton revised this gist Mar 24, 2022. 1 changed file with 38 additions and 0 deletions.
    38 changes: 38 additions & 0 deletions modify_screensharing.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,43 @@
    #!/bin/bash

    # A cleaner alternative to this approach, but which requires a restart, is to populate TCC's SiteOverrides.plist inside
    # the TCC app support directory with the following:
    # <?xml version="1.0" encoding="UTF-8"?>
    # <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    # <plist version="1.0">
    # <dict>
    # <key>Services</key>
    # <dict>
    # <key>PostEvent</key>
    # <array>
    # <dict>
    # <key>Allowed</key>
    # <true/>
    # <key>CodeRequirement</key>
    # <string>identifier "com.apple.screensharing.agent" and anchor apple</string>
    # <key>Identifier</key>
    # <string>com.apple.screensharing.agent</string>
    # <key>IdentifierType</key>
    # <string>bundleID</string>
    # </dict>
    # </array>
    # <key>ScreenCapture</key>
    # <array>
    # <dict>
    # <key>Allowed</key>
    # <true/>
    # <key>CodeRequirement</key>
    # <string>identifier "com.apple.screensharing.agent" and anchor apple</string>
    # <key>Identifier</key>
    # <string>com.apple.screensharing.agent</string>
    # <key>IdentifierType</key>
    # <string>bundleID</string>
    # </dict>
    # </array>
    # </dict>
    # </dict>
    # </plist>

    set -eux -o pipefail

    db_path="/Library/Application Support/com.apple.TCC/TCC.db"
  2. @timsutton timsutton revised this gist Dec 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion modify_screensharing.sh
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ sqlite3 "${db_path}" \
    "SELECT * FROM access WHERE client = 'com.apple.screensharing.agent';"
    }

    # uncomment this to show existing entries
    # uncomment to show existing entries for debugging
    # dump_screensharing_entries

    sanity_checks
  3. @timsutton timsutton revised this gist Dec 16, 2021. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion modify_screensharing.sh
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,12 @@ sqlite3 "${db_path}" \
    "SELECT * FROM access WHERE client = 'com.apple.screensharing.agent';"
    }

    # uncomment this to show existing entries
    # dump_screensharing_entries

    sanity_checks
    disable_screensharing

    enable_screensharing
    # uncomment to disable instead of enable
    # disable_screensharing

  4. @timsutton timsutton revised this gist Nov 12, 2021. 1 changed file with 12 additions and 13 deletions.
    25 changes: 12 additions & 13 deletions modify_screensharing.sh
    Original file line number Diff line number Diff line change
    @@ -20,34 +20,33 @@ sanity_checks() {
    # for whatever is the protection for TCC)
    }


    disable_screensharing() {
    launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
    sqlite3 "${db_path}" \
    "BEGIN TRANSACTION; \
    DELETE FROM access WHERE client = 'com.apple.screensharing.agent'; \
    COMMIT;"
    "BEGIN TRANSACTION; \
    DELETE FROM access WHERE client = 'com.apple.screensharing.agent'; \
    COMMIT;"
    }

    enable_screensharing() {
    launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist

    epoch="$(date +%s)"
    sqlite3 "${db_path}" \
    "BEGIN TRANSACTION; \
    DELETE FROM access WHERE client = 'com.apple.screensharing.agent'; \
    COMMIT; \
    BEGIN TRANSACTION; \
    INSERT INTO access VALUES('kTCCServicePostEvent','com.apple.screensharing.agent',0,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,${epoch}); \
    INSERT INTO access VALUES('kTCCServiceScreenCapture','com.apple.screensharing.agent',0,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,${epoch}); \
    COMMIT;"
    "BEGIN TRANSACTION; \
    DELETE FROM access WHERE client = 'com.apple.screensharing.agent'; \
    COMMIT; \
    BEGIN TRANSACTION; \
    INSERT INTO access VALUES('kTCCServicePostEvent','com.apple.screensharing.agent',0,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,${epoch}); \
    INSERT INTO access VALUES('kTCCServiceScreenCapture','com.apple.screensharing.agent',0,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,${epoch}); \
    COMMIT;"
    }


    dump_screensharing_entries() {
    sqlite3 "${db_path}" \
    "SELECT * FROM access WHERE client = 'com.apple.screensharing.agent';"
    "SELECT * FROM access WHERE client = 'com.apple.screensharing.agent';"
    }

    sanity_checks
  5. @timsutton timsutton revised this gist Nov 12, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions modify_screensharing.sh
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,8 @@ sanity_checks() {
    exit 1
    fi

    # TODO: we should bail if we determine we don't have write access to the TCC db (we want to get specific SIP disable status
    # for whatever is the protection for TCC)
    }


  6. @timsutton timsutton created this gist Nov 12, 2021.
    53 changes: 53 additions & 0 deletions modify_screensharing.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/bin/bash

    set -eux -o pipefail

    db_path="/Library/Application Support/com.apple.TCC/TCC.db"

    sanity_checks() {
    os_ver_major="$(sw_vers -productVersion | awk -F'.' '{print $1}')"
    if [[ "${os_ver_major}" -ne 12 ]]; then
    echo "This script is only tested valid on macOS 12, and we detected this system runs version ${os_ver_major}. Exiting."
    exit 1
    fi

    if [[ "$(id -u)" -ne 0 ]]; then
    echo "Need to run this script as root... exiting"
    exit 1
    fi

    }


    disable_screensharing() {
    launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
    sqlite3 "${db_path}" \
    "BEGIN TRANSACTION; \
    DELETE FROM access WHERE client = 'com.apple.screensharing.agent'; \
    COMMIT;"
    }

    enable_screensharing() {
    launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist

    epoch="$(date +%s)"
    sqlite3 "${db_path}" \
    "BEGIN TRANSACTION; \
    DELETE FROM access WHERE client = 'com.apple.screensharing.agent'; \
    COMMIT; \
    BEGIN TRANSACTION; \
    INSERT INTO access VALUES('kTCCServicePostEvent','com.apple.screensharing.agent',0,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,${epoch}); \
    INSERT INTO access VALUES('kTCCServiceScreenCapture','com.apple.screensharing.agent',0,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,${epoch}); \
    COMMIT;"
    }


    dump_screensharing_entries() {
    sqlite3 "${db_path}" \
    "SELECT * FROM access WHERE client = 'com.apple.screensharing.agent';"
    }

    sanity_checks
    disable_screensharing