how to rotate display monitor by applescript

  Kiến thức lập trình

enter image description here

My mac os is sonama 14.2.1, I want to auto rotate external display monitor,but I dont know how to switch to PHL 273v7 , I tried to get the page element。

button 1 of group 1 of group 2 of splitter group 1 of group 1 of window “显示器” of application process “System Settings” of application “System Events”,//this is ”排列” button

scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window “显示器” of application process “System Settings” of application “System Events”, // I guess this is right area

button 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window “显示器” of application process “System Settings” of application “System Events”, //display PHL 273v7(guess )

button 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window “显示器” of application process “System Settings” of application “System Events”` //display Built-in display(guess )

this is my code ,it can rotate build-in display,but not rotate other display

tell application "System Settings"
    # quit before system preference application
    quit
    delay 0.5 # delay for avoiding conflict
end tell
tell application "System Events"
    # open "Displays"(en) / "显示器"(zh) windows in system preferences
    key down {option}
    # must click with option on Monterey
    delay 0.5
    tell application "System Settings"
        # open new one
        activate
        delay 1
        set current pane to pane id "com.apple.Displays-Settings.extension"
        reveal
    end tell
    delay 1
    key up {option} # release option
end tell

set x to 0
tell application "System Events"
    tell application process "System Settings"
//here is not work ,dont switch to other display
        tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "显示器"
            click button 1
        end tell

        tell pop up button "旋转" of group 4 of scroll area 2 of group 1 of group 2 of splitter group 1 of group 1 of window "显示器"
            if value is "标准" then # 0-->90
                click
                delay 0.5
                pick menu item "90°" of menu 1
                set x to 0 # flag
            else # 90/180/270-->0
                click
                delay 0.5
                click menu item "标准" of menu 1
                set x to 90 # flag
            end if
        end tell
    end tell
end tell

tell application "System Events"
    # if 0-->90, a confirmation window with a countdown timer will appear
    delay 1
    if x = 0 then # if 0-->90
        click button 2 of group 1 of sheet 1 of window "显示器" of application process "System Settings" of application "System Events"
    end if
end tell

tell application "System Settings"
    # quit system preference application
    delay 0.5
    quit
end tell

LEAVE A COMMENT