javascript - Mac Underscan 调整编码问题 - AppleScript
问题描述
我尝试使用 AppleScript 将 Display > underscan 从 Off 调整到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
和参考照片
解决方案
我没有像你这样的设置来测试,但是,这就是我编码它的方式:
示例 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
笔记:
通常,a的值slider
介于0.0
和之间1.0
,因此我使用0.2
它应该最终到达您想要的位置,但是,请根据需要调整该值。
上面显示的示例 AppleScript 代码在macOS Catalina下的脚本编辑器中进行了测试,系统偏好设置中的语言和区域设置设置为英语(美国) - 主要并且为我工作,没有问题1。
- 1 假设系统偏好设置>安全和隐私>隐私中的必要和适当设置已根据需要进行设置/解决。
注意:示例 AppleScript 代码就是这样,并且没有任何包含的错误处理,不包含任何可能适当的额外错误处理。用户有责任根据需要或需要添加任何错误处理。查看AppleScript 语言指南中的try 语句和错误 语句。另请参阅处理错误。此外,在适当的情况下,可能需要在事件之间使用延迟命令,例如,使用延迟的值 delay 0.5
适当设置。
推荐阅读
- javascript - 单引号 (') 后的原子红色突出显示
- angular - 无法在应用模块中创建的子模块中实现路由
- spring-boot - Spring Boot 2.0.3 执行器与 Spring Boot 安全 CSRF 无效
- r - 正确评估列表列中的“rlang”表达式
- angular - Angular Universal - 排除路线
- r - Find the complement with the `subset` function in R
- javascript - 将数据格式化为文本,同时在数据表中向 excel 报告,但不工作
- java - 具有依赖注入错误的生产者/消费者模式
- sql - 有多少种方法可以生成将 varchar 转换为不会被 ISNUMERIC() 捕获的数字的错误?
- ssrs-2008 - 如何在 ssrs 单参数中创建父子层次结构