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
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 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.
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.
I'm trying to make an AppleScript to change an option in System Preferences. The checkbox is revealed by clicking "Mouse Options..." in the "Mouse and Trackpad" menu of the "Accessibility" pane. The script I have written so far is able to navigate through System Preferences so that the desired checkbox is visible to be clicked. However, I can't find a way to click the checkbox, seemingly because the checkbox is within a sort of 'drop down tab' on the window. None of the tutorials I have found online deal with this specific issue.
My code so far-
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.universalaccess"
get the name of every anchor of pane id "com.apple.preference.universalaccess"
reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
tell application "System Events" to tell process "System Preferences"
click button 5 of window "Accessibility"
end tell
end tell
The desired checkbox is "Scrolling". I expected that the following code would work, but it does not- it clicks checkboxes in the background, not the one in the tab.
tell application "System Events" to tell process "System Preferences"
click checkbox 1 of window "Accessibility"
end tell
This is my first time using AppleScript, I should mention. Any help would be much appreciated.
The 'drop down tab' is called a sheet:
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.universalaccess"
reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
tell application "System Events" to tell process "System Preferences"
click button 5 of window 1
click checkbox 1 of sheet 1 of window 1
end tell
end tell
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"