Osascript/Applescript:取消选中 "Displays have separate Spaces"

Osascript/Applescript: Uncheck "Displays have separate Spaces"

Mission Control 中 Mojave 10.14 的标准配置是 "Displays use separate spaces" 已选中。

我想取消选中...

有没有办法用 applescript/osascript 做到这一点?

这是我尝试过的,但它没有点击复选框..

if application "System Preferences" is running then quit application 
"System Preferences"
repeat until application "System Preferences" is not running
    delay 0.1
end repeat
tell application "System Preferences" to reveal pane id "com.apple.preference.expose"

tell application "System Events" to tell process "System Preferences" to 
tell window "Mission Control"
    repeat while not (exists of checkbox "Displays have separate Spaces")
        delay 0.1
    end repeat
    click checkbox "Displays have separate Spaces"
end tell

quit application "System Preferences"

当 运行 你的代码时,它停留在 repeat while not ... 循环中,因为目标 checkbox 不直接在 window 但属于 .

to tell group 2 添加到 to tell window "Mission Control" 修复它。

变化:

tell application "System Events" to tell process "System Preferences" to tell window "Mission Control"

收件人:

tell application "System Events" to tell process "System Preferences" to tell window "Mission Control" to tell group 2

注意:当 checking/unchecking 显示具有单独的空间 复选框时,需要注销才能使更改生效。