Search code examples
applescriptmacos-mojavesystem-preferences

Apple script to bring System Preferences pane to front


I am trying to navigate to security pane in system preferences using below script, if pane is already opened and minimised, script is not able to bring it front. Is there a way along with activation , I can bring it to front

tell application "System Preferences"
     activate
     set current pane to pane "com.apple.preference.security"
end tell

Solution

  • This script checks the state of the window.

    • If the window does not exist open it.
    • If the window exists but is miniaturized make it visible.
    • If the window is visible do nothing.

      tell application "System Preferences"
          activate
          if exists window "Security & Privacy" then
              tell window "Security & Privacy" to if it is miniaturized then set miniaturized to false
          else
              set current pane to pane "com.apple.preference.security"
          end if
      end tell