是否有任何苹果脚本将任务控制键盘选项设置为空?

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

完成步骤:

  1. 打开系统偏好设置
  2. 点击任务控制
  3. 在“键盘和鼠标快捷方式”标题下执行以下操作
  4. Select“-”表示任务控制
  5. Select "-" 表示申请 Windows
  6. Select "-" 表示显示桌面 注意:bigsur 需要 OS

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

以下脚本禁用任务控制并将快捷方式选项设置为空。

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

示例 AppleScript 代码,如下所示,在Script EditormacOS CatalinaLanguage & Region 设置在 System Preferences设置为 English (US) — Primary 并为我工作没有问题1.

  • 1 假定在 系统偏好设置 > 安全和隐私 > 隐私 已根据需要 set/addressed。

示例 AppleScript 代码:

--  # 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

注意:示例 AppleScript code 就是这样,没有包含任何 错误处理 不包含任何额外的 错误处理 可能是适当的。用户有责任根据需要或需要添加任何 错误处理 。查看 try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay 命令 在适当的事件之间可能是必要的,例如delay 0.5,适当设置延迟