Applescript to turn mirroring on and select iPad - applescript

I recently updated my mac to Monterey and my old applescript is not working anymore and I get this error: 'System Events got an error: Can’t get pop up button 1 of window 1 of process "System Preferences". Invalid index.'
I honestly have no idea which part should I change. Thank you in advance.
tell application "System Preferences"
set current pane to pane "com.apple.preference.displays"
activate
end tell
tell application "System Events"
tell process "System Preferences"
click pop up button 1 of window 1
click menu item 1 of menu 1 of pop up button 1 of window 1
end tell
end tell
tell application "System Preferences"
delay 10
quit
end tell

tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
activate
end tell
tell application "System Events"
tell application process "System Preferences"
click pop up button "Add Display" of window "Displays"
click menu item 2 of menu 1 of pop up button "Add Display" of window "Displays"
end tell
end tell
tell application "System Preferences"
delay 5
quit
end tell

Related

How to click on iCloud button in System Preferences using applescript

I am trying to get the script to click the iCloud button, but I am getting the syntax/logic incorrect.
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preferences.internetaccounts"
delay 1
end tell
tell application "System Events"
tell process "System Preferences"
click button "iCloud" of window "Internet Accounts"
end tell
end tell
Help is much appreciated. I am on Monterey (12,4) iMac.
Try this.
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preferences.internetaccounts"
end tell
tell application "System Events" to tell process "System Preferences"
repeat until exists of UI element "iCloud" of UI element 1 of row 1 of ¬
table 1 of scroll area 1 of group 1 of window "Internet Accounts"
delay 0.1
end repeat
click button "iCloud" of UI element 1 of row 1 of table 1 of scroll area 1 of ¬
group 1 of window "Internet Accounts"
end tell

Toggle HDR mode in macOS 12

tell application "System Preferences"
set the current pane to pane id "com.apple.preference.displays"
tell application "System Events"
tell window 1 of application process "System Preferences"
click checkbox "High Dynamic Range" of window "Displays" of application process "System Preferences" of application "System Events"
end tell
end tell
I'm using macOS 12.
It's not working. Help me please.
macos12
Thank you #Zade.
I solved it to use the UI Browser.
on run
activate application "System Preferences"
tell application "System Events"
tell process "System Preferences"
click button "Displays" of scroll area 1 of window "System Preferences"
delay 2
click checkbox "High Dynamic Range, Automatically adjust the display to show high dynamic range content." of group 1 of window "Displays"
end tell
delay 1
quit application "System Preferences"
end tell
end run

Show Bluetooth / Volume in menu bar Apple Script

I have a working script that I would like to see if there is a way to hide or simply have the script run in the background. The current working script physically activates the pane thus the user is seeing it happen in front of them.
tell application "System Preferences"
activate
set the current pane to pane "Bluetooth"
delay 1
end tell
tell application "System Events"
tell process "System Preferences"
set toggleBluetooth to the checkbox "Show Bluetooth in menu bar" of the window "Bluetooth"
click toggleBluetooth
end tell
end tell
I've also found a way to turn on certain things instantly and was wondering if there was a way to take this and make it work with the bluetooth and volume.
tell application "Finder"
tell Finder preferences
set desktop shows hard disks to true
end tell
end tell
This following AppleScript code can be used to toggle the Bluetooth menu bar item on and off, without bringing System Preferences to the front.
if application "System Preferences" is running then
do shell script "killall 'System Preferences'"
repeat until application "System Preferences" is not running
delay 0.1
end repeat
end if
tell application "System Preferences"
reveal anchor "Main" of pane id "com.apple.preferences.Bluetooth"
end tell
tell application "System Events"
repeat until checkbox "Show Bluetooth in menu bar" of window "Bluetooth" of application process "System Preferences" exists
delay 0.1
end repeat
click checkbox "Show Bluetooth in menu bar" of window "Bluetooth" of application process "System Preferences"
end tell
tell application "System Preferences" to quit
And this will do the exact same thing for the volume icon in the menu bar
if application "System Preferences" is running then
do shell script "killall 'System Preferences'"
repeat until application "System Preferences" is not running
delay 0.1
end repeat
end if
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events"
repeat until checkbox "Show volume in menu bar" of window "Sound" of application process "System Preferences" exists
delay 0.1
end repeat
click checkbox "Show volume in menu bar" of window "Sound" of application process "System Preferences"
end tell
tell application "System Preferences" to quit

Verify a checkbox before clicking with Applescript

I'm facing an issue with one of my applescript.
I'm trying to create an applescript that check/uncheck the checkbox that call the password after the mac wake up or the screensaver stop in the mac security pannel.
I'm using this with proximity.app, with the idea that when i'm back home and my phone is in range, proximity.app remove the password, but when i'm out of range, it put the password back.
Well... I'm forced to do it using UI scripting, because of the new security policy in Mountain Lion.
So there is the code when out of range :
tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
tell first window
tell first tab group
click radio button 1
if not 1 then click checkbox 1
click menu item 6 of menu of pop up button 1
end tell
end tell
end tell
end tell
quit
end tell
and when in range :
tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
tell first window
tell first tab group
click radio button 1
click checkbox 1
end tell
end tell
end tell
end tell
quit
end tell
What i want to improve, is a way to first verify if the box is check or uncheck before checking or unchecking it.
Thanks for your help.
Just check the value of the checkbox.
0 = Uncheck, 1 = check
tell application "System Preferences" to ¬
reveal anchor "Advanced" of pane id "com.apple.preference.security"
tell application "System Events"
tell first tab group of first window of process "System Preferences"
tell checkbox 1 to if value is 0 then click -- checkbox was not checked.
end tell
end tell
quit application "System Preferences"

Dropdown in Monitor System Preferences

tell application "System Events"
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.displays"
set theWindows to windows
set win2 to item 2 of theWindows
tell win2
set index to 1
set visible to false
set visible to true
end tell
set value of combo box 1 to "90°"
end tell
end tell
I'm trying to change the Rotation of the External Screen via Applescript, but I do
not find out how to access this dropdown menu. Google seems to give me a lot about combo box and pop menu, but under Lion at least all this stuff doesn't work.
This worked for me on 10.8.
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences"
tell pop up button 1 of tab group 1 of window 1
click
click menu item 3 of menu 1
end tell
end tell

Resources