Jump to content

Sidecar Toggle


Recommended Posts

  • 2 years later...
On 10/7/2022 at 10:03 AM, TomBenz said:

It doesn't work on Ventura. Anybody that can suggest a work around or script update? This is code where it is failing:

 

 

tell application "System Settings"

reveal pane id "com.apple.preference.displays"

end tell

 

Have you tried...

 

do shell script "open -b com.apple.systempreferences /System/Library/PreferencePanes/Displays.prefPane" ?

Link to comment
23 minutes ago, kraig85 said:

 

Have you tried...

 

do shell script "open -b com.apple.systempreferences /System/Library/PreferencePanes/Displays.prefPane" ?

Thanks. This is working. How to integrate this with the overall code? The underlined line is giving error.

 

do shell script "open -b com.apple.systempreferences /System/Library/PreferencePanes/Displays.prefPane"

 

use AppleScript version "2.4"

set iPadName to "iPad" -- TODO: Change to the name of your iPad

 

tell application "System Events"

tell process "System Preferences"

delay 0.8

click window "Displays"

tell pop up button "Add Display" of window "Displays"

click

delay 0.1

tell (last menu item of menu 1 whose name contains iPadName)

click it

end tell

end tell

end tell

end tell

 

tell application "System Settings" to close window 1

Link to comment

@TomBenz System Settings (i.e. on Ventura) are quite broken and not as automatable (let’s hope that is a ”yet”). You’re asking for help on doing GUI automation on unfinished software, so whatever you do now may turn out to be wasted. Plus, most people are not on Ventura, so there are fewer who can help. That is the nature and disadvantage of installing betas.

Link to comment
1 hour ago, vitor said:

@TomBenz System Settings (i.e. on Ventura) are quite broken and not as automatable (let’s hope that is a ”yet”). You’re asking for help on doing GUI automation on unfinished software, so whatever you do now may turn out to be wasted. Plus, most people are not on Ventura, so there are fewer who can help. That is the nature and disadvantage of installing betas.

thanks @vitorI understand and can wait for the official release of Ventura. I installed Ventura after public beta 8/9 recently and it has been working well. Alfred is also working without problem. Just fyi.

Link to comment
On 10/10/2022 at 6:06 AM, TomBenz said:

Thanks. This is working. How to integrate this with the overall code? The underlined line is giving error.

 

do shell script "open -b com.apple.systempreferences /System/Library/PreferencePanes/Displays.prefPane"

 

use AppleScript version "2.4"

set iPadName to "iPad" -- TODO: Change to the name of your iPad

 

tell application "System Events"

tell process "System Preferences"

delay 0.8

click window "Displays"

tell pop up button "Add Display" of window "Displays"

click

delay 0.1

tell (last menu item of menu 1 whose name contains iPadName)

click it

end tell

end tell

end tell

end tell

 

tell application "System Settings" to close window 1

As a temp work around (and hoping Vitor is right with the 'yet' part), I've used this script by placing the screen mirroring icon in the menu bar and copying from automator's watch me do - bearing in mind that my script has British English spellings of centre etc.)

 

-- Click the “Screen Mirroring” menu bar item. set timeoutSeconds to 2.0 set uiScript to "click menu bar item 6 of menu bar 1 of application process \"Control Centre\"" my doWithTimeout(uiScript, timeoutSeconds) -- Click the “<fill in title>” tickbox. set timeoutSeconds to 2.0 set uiScript to "click checkbox 3 of scroll area 1 of group 1 of window \"Control Centre\" of application process \"Control Centre\"" 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

Link to comment
On 11/3/2022 at 2:58 AM, Tony D said:

Did anyone get a script working in MacOS Ventura 13.0 yet?  

ta-da!!

 

do shell script "open -b com.apple.systempreferences /System/Library/PreferencePanes/Displays.prefPane"

use AppleScript version "2.4"

set iPadName to "iPad Pro"

tell application "System Events"

          repeat until (exists window "Displays" of application process "System Settings")

                    delay 0.1

          end repeat

          tell process "System Settings"

                    tell pop up button 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays"

                              click

                              delay 0.1

                              tell (last menu item of menu 1 whose name contains iPadName)

                                        click it

                             end tell

                    end tell

          end tell

end tell

tell application "System Settings" to quit

Link to comment
  • 4 weeks later...
  • 4 months later...
  • 1 month later...
On 12/13/2022 at 8:36 PM, peppy76 said:

hi, is there a way to use this script to share the screen to an appletv? the appletv is named "Wohnzimmer"?

 

Got this AppleScript from a website. It works well on macOS Ventura 13.2 and uses the control center GUI automation. The item that you click on is hardcode in the line - set uiScript to "click checkbox 1 of scroll area 1 of group 1 of window \"Control Center\" of application process \"Control Center\""

 

Perhaps it can be converted to a more generic workflow. For now, it serve my workflow requirement. @vitor @peppy76 @kraig85

 

Full AppleScript code:

-- 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

Edited by TomBenz
Link to comment
  • 1 month later...
On 11/10/2022 at 3:59 PM, kraig85 said:

ta-da!!

 

do shell script "open -b com.apple.systempreferences /System/Library/PreferencePanes/Displays.prefPane"

use AppleScript version "2.4"

set iPadName to "iPad Pro"

tell application "System Events"

          repeat until (exists window "Displays" of application process "System Settings")

                    delay 0.1

          end repeat

          tell process "System Settings"

                    tell pop up button 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Displays"

                              click

                              delay 0.1

                              tell (last menu item of menu 1 whose name contains iPadName)

                                        click it

                             end tell

                    end tell

          end tell

end tell

tell application "System Settings" to quit

Awesome. This script works on MacOS Sonoma as well. I did have to add a delay of 1 second before the quit system settings at the end because it was closing the settings panel before the display was activated but other than that it works as is. Amazing! 

Link to comment

Holy crap.  That java script is magic.  You guys are amazing!  Thank you for sharing.  The other script in this thread that I said was working suddenly stopped working and was giving me an error about "group 1" so I came back here and gave this javascript a try.  It looks so complicated compared to the other one but worked perfectly!  Really cool stuff.  Wish I could make stuff like that.  

Link to comment
4 hours ago, jacobwtyler said:

Holy crap.  That java script is magic.  You guys are amazing!  Thank you for sharing.  The other script in this thread that I said was working suddenly stopped working and was giving me an error about "group 1" so I came back here and gave this javascript a try.  It looks so complicated compared to the other one but worked perfectly!  Really cool stuff.  Wish I could make stuff like that.  

Works good for iPad. thanks. Getting error for iMac -- let me know tweak to screen mirror to iMac. @jacobwtyler

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...