Is there any apple script to set the mission control keyboard options to null?

Viewed 358

Steps to do:

  1. Open System Preferences
  2. Click on Mission Control
  3. Under the Heading "Keyboard and Mouse Shortcuts" do the following
  4. Select "-" for Mission Control
  5. Select "-" for Application Windows
  6. Select "-" for Show desktop Note: Required for bigsur OS

[Image][1] [1]: https://i.stack.imgur.com/syhEF.png

2 Answers

Following script disables mission controls and set the shortcut options to null.

tell application "System Preferences"
    activate
    delay 1
    set the current pane to pane id "com.apple.preference.expose"
    delay 1
    tell application "System Events"
          tell checkbox "Group windows by application" of group 2 of window "Mission Control" of application process "System Preferences"
               if (get its value) = 1 then click it
               tell application "System Events"
               tell checkbox "Automatically rearrange Spaces based on most recent use" of group 2 of window "Mission Control" of application process "System Preferences"
                    if (get its value) = 1 then click it
                    tell application "System Events"
                         tell checkbox "When switching to an application, switch to a Space with open windows for the application" of group 2 of window "Mission Control" of application process "System Preferences"
                              if (get its value) = 1 then click it
                              tell application "System Events"
                                   tell checkbox "Displays have separate Spaces" of group 2 of window "Mission Control" of application process "System Preferences"
                                        if (get its value) = 1 then click it
                                   end tell
                              end tell
                         end tell
                    end tell
               end tell
               end tell
          end tell
    end tell
    tell application "System Events" to tell process "System Preferences"
        tell  window "Mission Control"
            tell pop up button 1 of group 1
                if value is not "-" then
                    click
                    delay
                    pick menu item "-" of menu 1
                end if
            end tell
            tell pop up button 2 of group 1
                if value is not "-" then
                    click
                    delay
                    pick menu item "-" of menu 1
                end if
            end tell
            tell pop up button 3 of group 1
                if value is not "-" then
                    click
                    delay
                    pick menu item "-" of menu 1
                end if
            end tell
        end tell
    end tell
    quit
end tell

The example AppleScript code, shown below, was tested in Script Editor under macOS Catalina a with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.

  • 1 Assumes necessary and appropriate setting in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.

Example AppleScript code:

--  # Check to see if System Preferences is 
--  # running and if yes, then close it.
--  # 
--  # This is done so the script will not fail 
--  # if it is running and a modal sheet is 
--  # showing, hence the use of 'killall' 
--  # as 'quit' fails when done so, if it is.
--  #
--  # This is also done to allow default behaviors
--  # to be predictable from a clean occurrence.

if running of application "System Preferences" then
    try
        tell application "System Preferences" to quit
    on error
        do shell script "killall 'System Preferences'"
    end try
    delay 0.1
end if

--  # Make sure System Preferences is not running before
--  # opening it again. Otherwise there can be an issue
--  # when trying to reopen it while it's actually closing.

repeat while running of application "System Preferences" is true
    delay 0.1
end repeat

--  # Open System Preferences to Mission Control.

tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preference.expose"
end tell

tell application "System Events"
    tell window 1 of application process "System Preferences"
        
        --  Wait until UI ellements are available.
        
        set i to 0
        repeat until exists checkboxes of group 2
            delay 0.1
            set i to i + 1
            if i ≥ 30 then return
        end repeat
        
        --  # Uncheck any checked ckeckboxes.
        
        tell group 2
            repeat with i from 1 to count checkboxes
                if value of checkbox i is equal to 1 then click checkbox i
            end repeat
        end tell
        
        --  # Set all pop up buttons to: -
        
        tell group 1
            repeat with i from 1 to count pop up buttons
                if value of pop up button i is not "-" then
                    click pop up button i
                    pick menu item "-" of menu 1 of pop up button i
                end if
            end repeat
        end tell

    end tell
end tell

tell application "System Preferences" to quit

Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

Related