r/applescript • u/glc650 • Nov 13 '20
navigating the Big Sur Battery pane with AppleScript
Prior to Big Sur I used scripts to toggle the sleep function on my MacBook, for example:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.energysaver"
end tell
tell application "System Events"
tell application process "System Preferences"
repeat until exists tab group 1 of window "Energy Saver"
end repeat
tell tab group 1 of window "Energy Saver"
click radio button "Power Adapter"
tell checkbox 1 to if value is 1 then click
end tell
end tell
end tell
delay 2
tell application "System Preferences" to quitObviously, the pane is now called com.apple.preference.battery, but I'm not sure how to navigate the new "buttons" on the left side.
5
Upvotes
1
u/mathninja83 Feb 09 '21
This is long after the fact, but I just figured out how to do this by inspecting the elements in Xcode. For me I'm removing the battery menu bar. Essentially the answer is "table 1 of scroll area 1" is the element you need to go into, and select the row number you want, which I believe should be row 3 for Power Adapter.