Skip to content

Commit 7677502

Browse files
Add macOS screen recording permission fix in CI
Introduces a step to grant screen recording permissions on macOS runners by modifying the TCC database, preventing popup dialogs during CI runs. This ensures smoother automated workflows and addresses issues with screen capture access in GitHub Actions.
1 parent 77cbb4d commit 7677502

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

.github/workflows/ci.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,74 @@ jobs:
7878
ninja \
7979
node
8080
81+
- name: Fix macOS screen recording permissions
82+
if: runner.os == 'macOS'
83+
run: |
84+
# Grant screen recording permissions to prevent popup dialogs in CI
85+
# This modifies the TCC (Transparency, Consent, and Control) database
86+
87+
# https://apple.stackexchange.com/questions/362865/macos-list-apps-authorized-for-full-disk-access
88+
# https://github.com/actions/runner-images/issues/9529
89+
# https://github.com/actions/runner-images/pull/9530
90+
91+
# Get macOS version
92+
os_version=$(sw_vers -productVersion | cut -d '.' -f 1)
93+
echo "macOS version: $os_version"
94+
95+
# function to execute sql query for each value
96+
function execute_sql_query {
97+
local value=$1
98+
local dbPath=$2
99+
echo "Executing SQL query for value: $value"
100+
sudo sqlite3 "$dbPath" "INSERT OR IGNORE INTO access VALUES($value);"
101+
}
102+
103+
# Find all provisioner paths and store them in an array
104+
readarray -t provisioner_paths < <(sudo find /opt /usr -name provisioner)
105+
echo "Provisioner paths: ${provisioner_paths[@]}"
106+
107+
# Create an empty array
108+
declare -a values=()
109+
110+
# Loop through the provisioner paths and add them to the values array
111+
for p_path in "${provisioner_paths[@]}"; do
112+
# Adjust the service name and other parameters as needed
113+
values+=("'kTCCServiceAccessibility','${p_path}',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,NULL,1592919552")
114+
values+=("'kTCCServiceScreenCapture','${p_path}',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159")
115+
done
116+
echo "Values: ${values[@]}"
117+
118+
# Adjust for Sonoma (macOS 14+) which has extra columns
119+
if [[ "$os_version" -ge 14 ]]; then
120+
echo "Adjusting for macOS Sonoma or later (extra TCC columns)"
121+
# TCC access table in Sonoma has extra 4 columns: pid, pid_version, boot_uuid, last_reminded
122+
for i in "${!values[@]}"; do
123+
values[$i]="${values[$i]},NULL,NULL,'UNUSED',${values[$i]##*,}"
124+
done
125+
fi
126+
127+
# System and user TCC databases
128+
dbPaths=(
129+
"/Library/Application Support/com.apple.TCC/TCC.db"
130+
"$HOME/Library/Application Support/com.apple.TCC/TCC.db"
131+
)
132+
133+
# Execute SQL queries
134+
for value in "${values[@]}"; do
135+
for dbPath in "${dbPaths[@]}"; do
136+
echo "Column names for $dbPath"
137+
echo "-------------------"
138+
sudo sqlite3 "$dbPath" "PRAGMA table_info(access);"
139+
echo "Current permissions for $dbPath"
140+
echo "-------------------"
141+
sudo sqlite3 "$dbPath" "SELECT * FROM access WHERE service='kTCCServiceScreenCapture';"
142+
execute_sql_query "$value" "$dbPath"
143+
echo "Updated permissions for $dbPath"
144+
echo "-------------------"
145+
sudo sqlite3 "$dbPath" "SELECT * FROM access WHERE service='kTCCServiceScreenCapture';"
146+
done
147+
done
148+
81149
- name: Setup Dependencies Windows
82150
if: runner.os == 'Windows'
83151
uses: msys2/setup-msys2@4f806de0a5a7294ffabaff804b38a9b435a73bda # v2.30.0

0 commit comments

Comments
 (0)