1

Standard Configuration of Mojave 10.14 in Mission Control is, that "Displays use separate spaces" is checked.

I want it unchecked...

Is there a way to do this with applescript/osascript?

This is what i tried but its not clicking on the checkbox..

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"
samecat
  • 335
  • 1
  • 11
  • 1
    Your code as posted has two linefeeds that shouldn't be there, and one causes a compile error while the other causes Script Editor to want to quit. After fixing that and running the code, it stays in the `repeat while not ...` loop (on macOS High Sierra anyway) because the target checkbox is not directly under the window but a part of a group. Adding `to tell group 2` to `to tell window "Mission Control"` fixes it. Since I'm not running macOS Mojave yet, I can't confirm if this fixes it there too, but it gives you a direction to look. – user3439894 Nov 23 '18 at 11:56
  • 1
    BTW Under macOS High Sierra it requires a logout for the change to take effect, not sure if it's still required in macOS Mojave. – user3439894 Nov 23 '18 at 12:07
  • Thank you very much!!! It is working with "to tell window "Mission Control" to tell group 2". And yes, Mojave still requires a restart :) !!! You can post it as an answer if u want, so i can accept it – samecat Nov 23 '18 at 12:54

1 Answers1

1

When running your code, it stays in the repeat while not ... loop because the target checkbox is not directly under the window but a part of a group.

Adding to tell group 2 to to tell window "Mission Control" fixes it.

Change:

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

To:

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

Note: When checking/unchecking the Displays have separate Spaces checkbox, it requires a logout for the change to take effect.

user3439894
  • 7,266
  • 3
  • 17
  • 28