【问题标题】:Mac Underscan adjusment coding problem - AppleScriptMac Underscan 调整编码问题 - AppleScript
【发布时间】:2021-10-17 16:02:54
【问题描述】:

我尝试使用 AppleScript 调整显示 > underscan 从 Off 到 2nd level 的 underscan 设置栏。因为我的 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

和参考照片

【问题讨论】:

    标签: javascript macos applescript


    【解决方案1】:

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

    示例 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
    

    注意事项:

    通常,slider 介于 0.01.0 之间,所以我使用了 0.2,所以它应该会在你想要的位置结束,但是,调整 value 视需要而定。

    示例 AppleScript 代码,如上所示,在 ma​​cOS Catalina 下的 Script Editor 中进行了测试系统偏好设置 中的 语言和地区 设置设置为 英语(美国)- 主要 并且为我工作没有问题 1.

    • 1 假设 系统偏好设置 > 安全和隐私 > 隐私中的必要和适当的设置已设置/根据需要解决。


    注意:示例 AppleScript 代码就是这样,没有任何包含的错误处理 em> 不包含任何适当的附加错误处理。用户有责任根据需要或需要添加任何错误处理。查看AppleScript Language Guide 中的try statementerror statement。另请参阅Working with Errors。此外,在适当的情况下,可能需要在事件之间使用delay 命令,例如delay 0.5延迟设置得当。

    【讨论】:

    • 您好,感谢您的分享。我可以运行您的代码似乎可以打开并调整“欠扫描”。但无论我设置为 0.11 的值如何,“欠扫描”设置总是移动到 Off0
    • 嗨@user3439894,我又来了。我试图得到那个滑块值。发现默认值为7000,我将值设置为8000似乎对我有用。
    • @Terence Mak,将滑块设置到你想要的位置,获取它的值,然后在代码中使用它。
    猜你喜欢
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多