Catalina Sidecar toggle

Ich habe es gerade noch einmal getestet. Scheinbar ist bei einem deutschen System (oder dem Macbook Pro) noch ein Zwischenspeichern des Menüs notwendig. Sonst läuft es auf einen Fehler. Versuche es einmal hiermit:

tell application "System Events"
	tell process "SystemUIServer"
		try
			set btMenu to (menu bar item 1 of menu bar 1 whose description contains "Monitore")
			tell btMenu
				click
				tell (menu item 1 of menu 1 whose title contains "iPad")
					click
				end tell
			end tell
		on error
			display dialog "Cannot find any iPads available right now"
		end try
	end tell
end tell

(in der Action "Apple Script starten …" des Buttons)

Leider weiterhin die Meldung Cannot find any iPads

Wird denn das Menü "Monitore" in der Menübar angezeigt und erscheint in diesem Dein iPad?
Ohne Titel
Dann muss es eigentlich gehen.

Eventuell hilft noch ein Delay:

tell application "System Events"
	tell process "SystemUIServer"
		try
			set btMenu to (menu bar item 1 of menu bar 1 whose description contains "Monitore")
			tell btMenu
				click
				delay 0.3
				tell (menu item 1 of menu 1 whose title contains "iPad")
					click
				end tell
			end tell
		on error
			display dialog "Cannot find any iPads available right now"
		end try
	end tell
end tell

Ansonsten wüsste ich dann auch nicht weiter.

Jetzt geht es, ich wußte nicht das ich die Option in der Menüleiste Anzeigen einstellen muss. Wenn man es deaktiviert hat funktioniert es nicht, das ist ja was.

Danke für deine Hilfe

Das Script macht halt nichts anderes, als auf's Menü zu klicken. Manches geht mit direkten Befehlen und manches halt nur so.

Jetzt bin ich schlauer, vielen dank und ein schönes Wochenende

Das stimmt! Es gibt auch noch eine Script für „detecting Sidecar“

Und wo finde ich das Script oder wie sieht das aus?

Do you have a solution for this toggle in Big Sur?

Sidecar toggle for Big Sur:
(change iPadName to Your iPad name)

set iPadName to "iPad"

tell application "System Events"
	tell application process "ControlCenter"
		repeat with tElement in menu bar items of menu bar 1
			if (exists attribute "AXTitle" of tElement) then
				if value of attribute "AXTitle" of tElement contains "Display" then
					set theBar to tElement
					tell theBar
						click
					end tell
					set tElements to entire contents of window 1
					repeat with i from 1 to count of tElements
						set tElement to item i of tElements
						if (title of tElement contains iPadName) then
							tell tElement
								click
							end tell
							exit repeat
						end if
					end repeat
					tell theBar
						click
					end tell
					exit repeat
				end if
			end if
		end repeat
	end tell
end tell

Edit: Loop optimized

2 Likes

Thank you so much! Working flawlessly again! :slight_smile:

I can't seem to get it to work with the Big Sur update above. My iPad name is separated with spaces and used and ".
olo's 12" iPad.

Do I need to enter that a specific way to get this to work?

You can check the following:

  • You can specific the iPad name in the first line of the script (set iPadName to …). Otherwise the first entry with contains "iPad" will bee used
  • Maybe it does not work if the iPad name contains a character like ", because this is the string separator
  • The menu "Display" (̶c̶̶h̶̶e̶̶c̶̶k̶̶b̶̶o̶̶x̶̶ ̶"̶s̶̶h̶̶o̶̶w̶̶ ̶̶m̶̶i̶̶r̶̶r̶̶o̶̶r̶̶i̶̶n̶̶g̶̶ ̶̶o̶̶p̶̶t̶̶i̶̶o̶̶n̶̶s̶̶ ̶̶i̶̶n̶̶ ̶̶t̶̶h̶̶e̶̶ ̶̶m̶̶e̶̶n̶̶u̶̶ ̶̶b̶̶a̶̶r̶̶ ̶̶w̶̶h̶̶e̶̶n̶̶ ̶̶a̶̶v̶̶a̶̶i̶̶l̶̶a̶̶b̶̶l̶̶e̶"̶ ̶̶i̶̶n̶̶ ̶̶s̶̶e̶̶t̶̶t̶̶i̶̶n̶̶g̶̶s̶̶ ̶-->̶ ̶̶d̶̶i̶̶s̶̶p̶̶l̶̶a̶̶y̶̶s̶ Edit: Settings -> Dock & Menu bar -> Display) must be always visible in the menu bar

Edit:

You can trial this:

set iPadName to "olo's 12\" iPad."

or leave default value to:

set iPadName to "iPad"

Thanks I changed my iPad name to make it easier without any special characters. Still doesn't work. For some reason even with the box checked to always show mirroring options the icon is not in the menu bar unless I go to settings and turn on the mirroring or Sidecar.

Try this:

  • Open settings -> Dock & Menu bar
  • Click Display on the left site
  • Enable Checkbox "Show in menu bar"
  • Select "always" in the Drop Down field

Then the script must be work.

Guys, some major updates today. It's now language independent, and will select your iPad by default. No need to input your iPad name.

tell application "System Events"
	tell process "ControlCenter"
		try
			perform action "AXPress" of menu bar item "Control Center" of menu bar 1
		on error
			display dialog "Please make sure you are using macOS Big Sur and have Control Center showing on your menu bar"
		end try
		try
			tell checkbox 6 of group 1 of group 1 of window 1
				perform action "AXPress"
			end tell
			delay 1
		on error
			display dialog "Cannot find Displays in your control center"
		end try
		try
			tell checkbox 4 of group 1 of group 1 of window 1
				perform action "AXPress"
			end tell
		on error
			display dialog "Cannot find your ipad"
		end try
	end tell
end tell

For those are also using Alfred, this is my preset

1 Like

Seems to not be working again in MacOS 12.0.1

Everything seems to work as before, but will not select the iPad from the menu.

The Control Center no longer responds to click events from any script. But the version with the menu bar should still work with a small change.

Try this (I couldn't test it as I don't currently have an iPad):

set iPadName to "iPad"

tell application "System Events"
	tell application process "ControlCenter"
		repeat with tElement in menu bar items of menu bar 1
			if (exists attribute "AXTitle" of tElement) then
				if value of attribute "AXTitle" of tElement contains "Display" then
					set theBar to tElement
					tell theBar
						click
					end tell
					set tElements to entire contents of window 1
					set tElements to entire contents of window 1 -- bug in 12.x
					repeat with i from 1 to count of tElements
						set tElement to item i of tElements
						if (title of tElement contains iPadName) then
							tell tElement
								click
							end tell
							exit repeat
						end if
					end repeat
					tell theBar
						click
					end tell
					exit repeat
				end if
			end if
		end repeat
	end tell
end tell

Note: The menu "Display" (Settings -> Dock & Menu bar -> Display) must be always visible in the menu bar. See: Catalina Sidecar toggle - #23 by Dirk

1 Like

Can confirm that this does work. Wanted to follow up so that any others can know the answer is here.

Thanks!

Unfortunately this doesn't work on Monterey. Would be nice to have, and a toggle to enable/disable Universal Controls.