AirControl icon indicating copy to clipboard operation
AirControl copied to clipboard

Doesn't work on Big Sur

Open namchuai opened this issue 3 years ago • 4 comments

Thanks for this great tool. I tried but it does not seems to work on BigSur.

1179:1254: execution error: System Events got an error: Can’t get menu bar 1 of process "SystemUIServer". Invalid index. (-1719)

namchuai avatar May 17 '21 09:05 namchuai

When run on Monterey.

1206:1281: execution error: System Events got an error: Can’t get menu bar item 1 of menu bar 1 of process "SystemUIServer" whose description contains "Displays". Invalid index. (-1719)

kevindiffily avatar Jan 30 '22 23:01 kevindiffily

I also get this with Monterey:

1161:1236: execution error: System Events got an error: Can’t get menu bar 1 of process "SystemUIServer". Invalid index. (-1719)

calvin-barker avatar Mar 22 '22 14:03 calvin-barker

@kevindiffily If you still care about this, I ultimately changed everything in /aircontrol for Monterey, so hopefully this helps:

#!/usr/bin/env bash

tvname="Samsung 8 series"

read -d '' APPLESCRIPT <<EOF

tell application "System Preferences"
   if not running then run
   activate
   reveal anchor "displaysArrangementTab" of pane id "com.apple.preference.displays"

end tell

tell application "System Events"
   tell process "System Preferences"
      click window "Displays"
      tell pop up button "Add Display" of window "Displays"
         click
         click menu item \"$tvname\" of menu 1
      end tell
   end tell
end tell

EOF

osascript -e "$APPLESCRIPT" > /dev/null

(I'll have to open a PR later to make it better)

calvin-barker avatar Mar 22 '22 14:03 calvin-barker

It does not work on Ventura. I used Automator to generate AppleScript that works most of the time:

-- Click the “Screen Mirroring” menu bar item.
-- delay 2.130212
set timeoutSeconds to 2.0
set uiScript to "click menu bar item 7 of menu bar 1 of application process \"Control Center\""
my doWithTimeout(uiScript, timeoutSeconds)

-- Click the “<fill in title>” checkbox.
-- delay 0.988109
set timeoutSeconds to 2.0
set uiScript to "click checkbox 1 of scroll area 1 of group 1 of window \"Control Center\" of application process \"Control Center\""
my doWithTimeout(uiScript, timeoutSeconds)

-- Type ''
-- delay 1.04737
set timeoutSeconds to 2.0
set uiScript to "keystroke \"\""
my doWithTimeout(uiScript, timeoutSeconds)


on doWithTimeout(uiScript, timeoutSeconds)
	set endDate to (current date) + timeoutSeconds
	repeat
		try
			run script "tell application \"System Events\"
" & uiScript & "
end tell"
			exit repeat
		on error errorMessage
			if ((current date) > endDate) then
				error "Can not " & uiScript
			end if
		end try
	end repeat
end doWithTimeout

However, I can't find a way to hard-code the menu time in Control Center, so we can consistently select the correct Airplay receiver using the CLI argument. It appears GUI scripting got more difficult with Ventura: https://stackoverflow.com/questions/71691357/open-screen-mirroring-in-control-center-for-sidecar

jgenunez avatar Jan 09 '23 23:01 jgenunez