Mac 欠扫描调整编码问题 - AppleScript

Mac Underscan adjusment coding problem - AppleScript

我尝试使用 AppleScript 将欠扫描设置栏的显示 > 欠扫描从关闭调整到第 2 级。因为我的 Mac Mini 每次打开电视或从睡眠中醒来时都会自动关闭欠扫描设置。

我参考了一些网上的代码,确实做了打开“设置”和“显示”标签的代码,但我不知道下一步是什么。有谁知道其他编码应该是什么?

我的代码:

activate application "System Preferences"
tell application "System Events"
    tell process "System Preferences"
        click button "Displays" of scroll area 1 of window "System Preferences"
        delay 0.5
        
        tell tab group 1 of window "42PFD5519/30"
            click radio button "Default for Display"
            
            -- What code should i use?
            
        end tell
    end tell
    delay 0.5
    quit application "System Preferences"
end tell

和参考照片

我没有像你这样的设置来测试,但是,我是这样编码的:

示例 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 the 
--  # Display tab of the Displays pane. 

tell application "System Preferences" to ¬
    reveal anchor "displaysDisplayTab" of ¬
        pane id "com.apple.preference.displays"

tell application "System Events"
    tell application process "System Preferences"
        
        --  # Wait for the UI to be available.

        set i to 0
        repeat until exists ¬
            radio button 1 of ¬
            tab group of window 1
            delay 0.1
            set i to i + 1
            if i ≥ 30 then return
        end repeat

        --  # Click the target radio button
        --  # and adjust the target slider.
        
        tell tab group 1 of window 1
            click radio button "Default for display"
            set value of slider 1 to 0.2
        end tell
        
    end tell
end tell

delay 0.2

tell application "System Preferences" to quit

备注:

一般情况下,slider0.01.0之间,所以我用了0.2所以它应该在您想要的位置结束,但是,请根据需要调整

上面显示的示例AppleScript代码在[=43=中进行了测试macOS Catalina 下的 ]Script Editor 以及 System Preferences 中的 Language & Region 设置到 英语(美国)— 小学 并为我工作没有问题1.

  • 1 系统偏好设置 > 安全与隐私[=] 中假定必要且适当的设置64=] > 隐私 已根据需要 set/addressed。


注意:示例 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,适当设置延迟