title: Change MacBook screen scaling via AppleScript
body: <p>I am trying to change my MacBook Pro 14&quot;s scale setting via AppleScript.<br />
  The setting should toggle two resolution settings.<br />
  I found the following script here: <a href="https://stackoverflow.com/a/62664159/15705553">https://stackoverflow.com/a/62664159/15705553</a></p>
  <pre><code>on run {input, parameters}
      
      tell application &quot;System Preferences&quot;
          reveal anchor &quot;displaysDisplayTab&quot; of pane &quot;com.apple.preference.displays&quot;
      end tell
      
      set lowResolutionSettingIndex to 4
      set highResolutionSettingIndex to 5
      
      tell application &quot;System Events&quot; to tell process &quot;System Preferences&quot; to tell window &quot;Built-in Retina Display&quot;
          click radio button &quot;Display&quot; of tab group 1
          click radio button &quot;Scaled&quot; 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 - &quot;Retina optimized&quot;
              click radio button highResolutionSettingIndex of radio group 1 of group 1 of tab group 1
          end if
      end tell
      
      quit application &quot;System Preferences&quot;
      
      return input
  end run
  </code></pre>
  <p>I changed &quot;Built-in Retina display&quot; to &quot;Built-in Liquid Retina XDR Display&quot; as shown in my System Preferences, but two errors occur:</p>
  <ul>
  <li>If I execute this script through Automator, I get the following error:</li>
  </ul>
  <pre><code>Syntax Error: System Events got an error: Can’t get window &quot;Built-in Liquid Retina XDR Display&quot; of process &quot;System Preferences&quot;.
  </code></pre>
  <ul>
  <li>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</li>
  </ul>
  <pre><code>System Events got an error: Shortcuts is not allowed assistive access.
  </code></pre>