I have found a hack that works without disabling SIP or modifying our workflow.
I revisited the AppleScript clicker idea since it seemed the most boring and easiest to peel back if Apple makes a fix in the future.
I had issues with it last time since I was trying to run it within the CI workflow, but in the background since I didn't want to block execution of the actual xcodebuild ... test command, but I needed the script running before the tests kicked off in order to accept the dialog. See the following quote
[quote='844634022, brian-bcny, /thread/787469?answerId=844634022#844634022, /profile/brian-bcny']
I've tried running this as a simple shell script osascript /path/to/clicker.scpt & and through launchd with launchctl asuser $(id -u) /path/to/clicker.scpt &. I also tried using the launchctl version without putting the script in the background, but that didn't seem to work either.
[/quote]
I suppose the problem with that approach is that the script is running in the background which means it can't click anything actually.
So instead, I've created another LaunchAgent that just runs the clicker script when the user logs in and will restart it if it fails. The agent looks like this:
<?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>Label</key>
<string>company.thebrowser.local-network-privacy-clicker</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>/Users/{your-ci-user}/click-local-network-popup.scpt</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/thbrws/logs/company.thebrowser.local-network-privacy-clicker.log</string>
<key>StandardErrorPath</key>
<string>/tmp/thbrws/logs/company.thebrowser.local-network-privacy-clicker.log</string>
</dict>
</plist>
While the actual AppleScript looks like this:
(*
Continuously click "Allow" on macOS network-privacy dialogs.
Save as: allow-network-dialogs-continuous.scpt
Run with: osascript allow-network-dialogs-continuous.scpt
This script will keep running indefinitely, clicking any matching
dialogs as they appear. Use Ctrl+C to stop it.
*)
-- Configuration
property pollInterval : 0.3 -- how often (in seconds) to check
property anchorText : "find devices on local networks" -- identifying text
property logActivity : true -- whether to log when dialogs are clicked
-- Statistics
property dialogsClicked : 0
property startTime : missing value
on run
set startTime to (current date)
set dialogsClicked to 0
if logActivity then
log "Starting continuous network dialog monitor..."
log "Press Ctrl+C to stop"
end if
-- Run indefinitely
repeat
if (my clickMatchingDialog()) then
set dialogsClicked to dialogsClicked + 1
if logActivity then
set runtime to ((current date) - startTime)
log "Clicked dialog #" & dialogsClicked & " after " & runtime & " seconds"
end if
end if
delay pollInterval
end repeat
end run
on clickMatchingDialog()
tell application "System Events"
-- Look through every window of every process
repeat with proc in (every process)
try
repeat with win in (windows of proc)
-- Quick check: does this window have an "Allow" button?
if (exists button "Allow" of win) then
-- Get all visible text from the window
set allText to ""
try
set allText to (value of static texts of win) as string
on error
-- Some windows have no static texts
end try
-- Is it the network-privacy dialog we're looking for?
if allText contains anchorText then
-- Click the Allow button
click button "Allow" of win
-- Optional: log which app triggered the dialog
if logActivity then
try
set appName to name of proc
log " Dialog was from: " & appName
on error
-- Couldn't get app name
end try
end if
return true
end if
end if
end repeat
on error
-- Skip any processes that cause errors
end try
end repeat
end tell
return false
end clickMatchingDialog
-- Optional: Handle script termination gracefully
on quit
if logActivity and (startTime is not missing value) then
set totalRuntime to ((current date) - startTime)
log "Stopped after " & totalRuntime & " seconds"
log "Total dialogs clicked: " & dialogsClicked
end if
continue quit
end quit
This is obviously a very ugly hack, and I'd love to replace it once I hear back with a more official solution/workaround, or some clarification on any of the assumptions I have made so far.
Topic:
App & System Services
SubTopic:
Networking
Tags: