I am trying to change my MacBook Pro 14"s scale setting via AppleScript.
The setting should toggle two resolution settings.
I found the following script here: https://stackoverflow.com/a/62664159/15705553
on run {input, parameters}
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
set lowResolutionSettingIndex to 4
set highResolutionSettingIndex to 5
tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
click radio button "Display" of tab group 1
click radio button "Scaled" of tab group 1
tell radio group 1 of group 1 of tab group 1
set isHighResolutionSet to get value of radio button highResolutionSettingIndex
end tell
if isHighResolutionSet then
-- Toggle native resolution
click radio button lowResolutionSettingIndex of radio group 1 of group 1 of tab group 1
else
-- Toggle Default setting - "Retina optimized"
click radio button highResolutionSettingIndex of radio group 1 of group 1 of tab group 1
end if
end tell
quit application "System Preferences"
return input
end run
I changed "Built-in Retina display" to "Built-in Liquid Retina XDR Display" as shown in my System Preferences, but two errors occur:
If I execute this script through Automator, I get the following error:
Syntax Error: System Events got an error: Can’t get window "Built-in Liquid Retina XDR Display" of process "System Preferences".
If I execute it through shortcuts.app, I get the following error, even though I granted access to accessibility features for Shortcuts in System Preferences
System Events got an error: Shortcuts is not allowed assistive access.
Here's how I select the first monitor in the list (Macbook Pro Built-in Retina Display) to gain access to the settings such as screen scaling:
tell application "System Preferences"
activate
reveal anchor "universalControlTab" of pane id "com.apple.preference.displays"
end tell
tell application "System Events"
tell application process "System Preferences"
tell window "Displays"
select row 1 of outline 1 of scroll area 1 of sheet 1
end tell
end tell
end tell
And to select the second monitor in the list if you want to gain access to those settings:
tell application "System Preferences"
activate
reveal anchor "universalControlTab" of pane id "com.apple.preference.displays"
end tell
tell application "System Events"
tell application process "System Preferences"
tell window "Displays"
select row 2 of outline 1 of scroll area 1 of sheet 1
end tell
end tell
end tell
Cheers.
Related
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
I'm trying to create an Automation Shortcut that toggles the fn keys in the Touch Bar.
This is my approach so far:
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
//TO-DO: script that opens drop down menu in settings and changes it to display fn buttons
end tell
This is the code that i use for Catalina OS:
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
reveal anchor "keyboardTab" of pane id "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences"
delay 0.3
set thePopUp to pop up button 2 of tab group 1 of window "Keyboard"
set current to value of thePopUp
click thePopUp
if current is equal to "F1, F2, etc. Keys" then
click menu item 1 of menu 1 of thePopUp
else
click menu item 3 of menu 1 of thePopUp
end if
end tell
quit application "System Preferences"
For anyone else trying to make this work - I've finally gotten my solution to work. Tested with: MacOS Big Sur, 11.4, June 2021
The code is based here:
https://github.com/MrSimonC/Toggle-Mac-Function-Keys
but for brevity, here is the contents of the apple script file:
-- Apple Script (i.e. Use in Apple's Script Editor Application) to Toggle Function Keys / Media keys on/off
-- Tested on MacOS Big Sur (11.4) June 2021
-- Project Path: https://github.com/MrSimonC/Toggle-Mac-Function-Keys
tell application "System Preferences"
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
if UI elements enabled then
tell application process "System Preferences"
repeat until exists tab group 1 of window "Keyboard"
delay 0.5
end repeat
click radio button "Keyboard" of tab group 1 of window "Keyboard"
click checkbox "Use F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
end tell
tell application "System Preferences" to quit
else
-- GUI scripting not enabled. Display an alert
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.security"
display dialog "UI element scripting is not enabled. Please activate this app under Privacy -> Accessibility so it can access the settings it needs."
end tell
end if
end tell
Hope someone finds it useful!
Simon.
How to set System Preferences-> Display -> Scaled -> More Space with the help of AppleScript?
I got till:
tell application "System Events"
tell process "System Preferences"
set frontmost to true
click button "Displays" of scroll area 1 of window "System Preferences"
click radio button "Scaled" of radio group 1 of tab group 1 of window "Built-in Retina Display"
But not sure how to set the " More Space" option?
TIA
try this:
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
click radio button "Display" of tab group 1
click radio button "Scaled" of radio group 1 of tab group 1
click radio button 4 of radio group 1 of group 2 of tab group 1
end tell
quit application "System Preferences"
A small command line script to change screen resolutions on macOs Sierra
#!/usr/bin/osascript
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
click radio button "Display" of first tab group
click radio button "Scaled" of first radio group of first tab group
tell first radio group of second group of first tab group
set isDefault to get value of second radio button
end tell
if isDefault then
click last radio button of first radio group of second group of first tab group
else
click second radio button of first radio group of second group of first tab group
end if
end tell
tell application "System Preferences"
quit
end tell
I want to issue a keyboard command to toggle the checkbox "Change picture every 30 minutes" in OS X for Desktop 1 (my main monitor desktop). I have multiple monitors so it may be necessary to identify which particular preference pane to manipulate.
I have set up the start of an AppleScript, but I'm at a loss how to formulate how to identify this particular check box:
tell application "System Preferences"
activate
end tell
tell application "System Events"
tell process "System Preferences"
click menu item "Desktop & Screen Saver" of menu "View" of menu bar 1
delay 2
tell window "Desktop & Screen Saver"
click checkbox 1 of …
It's in tab group 1. You can recognize this with the help of the Xcode tool Accessibility Inspector (Xcode > Open Developer Tool > Accessibility Inspector in the menu bar or Dock).
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.desktopscreeneffect"
end tell
delay 2
tell application "System Events" to tell process "System Preferences"
click checkbox "Change picture:" of tab group 1 of window "Desktop & Screen Saver"
end tell
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