AppleScript DisplayMenu / Sidecar via shortcut and script

Greetings!


I've got an old script, that doesn't seem to be compatible with MacOS Ventura.

I'm not really into AppleScript so explanation would also be very helpful! - thanks in advance!


The Problem:

I need a script that automatically starts sidecar on my Macbook, currently my screen is broken so I made a shortcut on my iPad that would allow me to run a script on my MacBook remotely - wich in theory should start connecting my MacBook with my iPad and use it as a external display (via Sidecar).


Current Output of the script:

Index of SystemUIServer can not be read...

The script:

activate application "SystemUIServer"
tell application "System Events"
    tell process "SystemUIServer"
        set displayMenu to (menu bar item 1 of menu bar 1 whose description contains "Displays")
        tell displayMenu
            click
            delay 1
            tell (menu item "myIpadName" of menu 1)
                click
            end tell
        end tell
    end tell
end tell

Posted on Sep 3, 2023 1:20 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 7, 2023 1:06 AM

After trying and failing a lot I finally found a solution to this problem! Version running on macOs Ventura 13.5


I modified the script because it seems, that the Settings app is poorly supporting AppleScript, wich lead to a lot of issues. -> Script now not working with the settings app, but rather using the "Control Center" in the head bar of MacOs.


tell application "System Events"
	
	tell its application process "ControlCenter"
		
		tell its menu bar 1
			-- click on and open Control Center drop down
			tell (UI elements whose description is "Kontrollzentrum")
				click
			end tell
		end tell
		
		
		-- interact with Control Center window
		tell its window "Kontrollzentrum"
			delay 0.5
			-- click screen mirroring button
			set screenMirroringButton to button 2 of group 1
			-- click screenMirroringButton click doesn't work
			perform action 1 of screenMirroringButton
			delay 0.5
			set myScreen to checkbox 1 of its scroll area 1 of group 1
			perform action 1 of myScreen
		end tell
		
		
	end tell
end tell

Note that "Kontrollzentrum" is the german term for "Control Center", change it to term used by your system. In English it should be "Control Center".


After I got this script to run in AppleScript I tried starting it from the iPad via a schortcut (run script via ssh).

The shortcut contains a single line of instruction:

osascript ~Directory/scriptName.scpt


After trying to start it I got an error on my iPad quoting:

error: osaysscript ist not allowed assistive access (-1719) / osaysscript hat keine Berechtigungen für Hilfszugriff (-1719)


You have to give BOTH Terminal as well as ssh-keygen-wrapper the rights to use assistive access:


Open settings app -> go to Security Settings -> accessibility Settings -> give ssh-keygen-wrapper & terminal (maybe AppleScript as well, just to be sure) the rights!


Einstellungen öffnen -> Datenschutz & Sicherheit -> Bedienungshilfen -> sshkeygen-wrapper & Terminal die Berechtigungen erteilen (zur Sicherheit auch AppleScript).


Now it should work! Have fun!


-- for any changes in my script look up my gitHub account ManuelTDev, I should have posted a repo (Sidecar_via_ssh) in there and also some documentation!

Similar questions

3 replies
Question marked as Top-ranking reply

Sep 7, 2023 1:06 AM in response to naahm

After trying and failing a lot I finally found a solution to this problem! Version running on macOs Ventura 13.5


I modified the script because it seems, that the Settings app is poorly supporting AppleScript, wich lead to a lot of issues. -> Script now not working with the settings app, but rather using the "Control Center" in the head bar of MacOs.


tell application "System Events"
	
	tell its application process "ControlCenter"
		
		tell its menu bar 1
			-- click on and open Control Center drop down
			tell (UI elements whose description is "Kontrollzentrum")
				click
			end tell
		end tell
		
		
		-- interact with Control Center window
		tell its window "Kontrollzentrum"
			delay 0.5
			-- click screen mirroring button
			set screenMirroringButton to button 2 of group 1
			-- click screenMirroringButton click doesn't work
			perform action 1 of screenMirroringButton
			delay 0.5
			set myScreen to checkbox 1 of its scroll area 1 of group 1
			perform action 1 of myScreen
		end tell
		
		
	end tell
end tell

Note that "Kontrollzentrum" is the german term for "Control Center", change it to term used by your system. In English it should be "Control Center".


After I got this script to run in AppleScript I tried starting it from the iPad via a schortcut (run script via ssh).

The shortcut contains a single line of instruction:

osascript ~Directory/scriptName.scpt


After trying to start it I got an error on my iPad quoting:

error: osaysscript ist not allowed assistive access (-1719) / osaysscript hat keine Berechtigungen für Hilfszugriff (-1719)


You have to give BOTH Terminal as well as ssh-keygen-wrapper the rights to use assistive access:


Open settings app -> go to Security Settings -> accessibility Settings -> give ssh-keygen-wrapper & terminal (maybe AppleScript as well, just to be sure) the rights!


Einstellungen öffnen -> Datenschutz & Sicherheit -> Bedienungshilfen -> sshkeygen-wrapper & Terminal die Berechtigungen erteilen (zur Sicherheit auch AppleScript).


Now it should work! Have fun!


-- for any changes in my script look up my gitHub account ManuelTDev, I should have posted a repo (Sidecar_via_ssh) in there and also some documentation!

Sep 4, 2023 1:33 PM in response to naahm

Current update:

-seems to be a more advanced version that I found, yet still fails at the same point

tell application "System Events"
	tell process "SystemUIServer"
		click (menu bar item 1 of menu bar 1 whose description contains "Displays")
		click menu item "iPad von Emanuel" of menu 1 of result
	end tell
end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript DisplayMenu / Sidecar via shortcut and script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.