2

After setting accessibility ON, I am trying to Mirror Displays using the following objective-c code with apple script:

- (void) toggleMirrorDisplayOption
{
    NSString *script = @"\
    tell application \"System Preferences\"\n\
        set current pane to pane \"com.apple.preference.displays\"\n\
        activate\n\
    end tell\n\
    tell application \"System Events\" to tell window 0 of process \"System Preferences\"\n\
        try\n\
            tell tab group 1 to click radio button \"Arrangement\"\n\
                tell group 1 of tab group 1\n\
                    click checkbox \"Mirror Displays\"\n\
                end tell\n\
        on error\n\
            return \"Only one display available.\"\n\
        end try\n\
    end tell";

    NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:script];
    [scriptObject executeAndReturnError:nil];
}

With this code I am just getting the Display Preferences > Arrangement window open.

How to perform click checkbox to mirror displays ?

Is it possible to perform it without opening this window ? If Yes, then How?

Thanks in advance.

Piyush Mathur
  • 1,617
  • 16
  • 33

0 Answers0