gpt4 book ai didi

applescripting 显示首选项面板

转载 作者:行者123 更新时间:2023-12-05 05:23:25 25 4
gpt4 key购买 nike

我正在尝试编写一个我认为可以更改显示器颜色配置文件的简单脚本。我已经调出 Displays 首选项面板并选择了 Color 选项卡,但随后遇到了真正的问题。遗憾的是,我缺少 GUI 脚本,我不知道如何选择显示配置文件。滚动窗口中仅显示两个配置文件(“iMac”和“我的校准 10-14”)。理想情况下,我希望脚本每次运行时都能在两个配置文件之间切换。这是我目前所拥有的:

tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.displays"
reveal (first anchor of current pane whose name is "displaysColorTab")
end tell

我们将不胜感激任何帮助或建议。我正在运行 OS 10.11.5

最佳答案

有了这个良好的开端,您离目标不远了。然后脚本应该找到哪一行包含配置文件 1 (iMac),哪一行包含配置文件 2(您的配置文件)。如果选择了包含配置文件 1 的行,则选择包含配置文件 2 的行。

下面的脚本就是这样做的。您必须调整 Prof1 和 Prof2 中的 2 个配置文件。该脚本使用“包含”,因此您不必将 prof1/2 设置为完整值,只需设置其中的一部分即可。

我还寻找 2 个配置文件之一不存在的情况(然后脚本不执行任何操作)。

tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.displays"
reveal (first anchor of current pane whose name is "displaysColorTab")
end tell

set Prof1 to "iMac" -- define the profile 1
set Prof2 to "ACES CG Linear" -- define the profile 2
set {Row1, Row2, Sel1} to {0, 0, false} -- init values

tell application "System Events"
tell application process "System Preferences"
tell table of scroll area 1 of tab group 1 of front window
-- search the 2 profiles in the list of rows
repeat with I from 1 to (count of rows)
set N to (value of static text of row I) as string
if N contains Prof1 then
set Row1 to I
set Sel1 to selected of row I
end if
if N contains Prof2 then set Row2 to I
end repeat
-- make the toggle !
if Sel1 then -- profile 1 selected, then select profile 2, if found
if Row2 > 0 then set selected of row Row2 to true
else -- profile 1 not yet selected, : select profile 1 if found
if Row1 > 0 then set selected of row Row1 to true
end if
end tell -- table
end tell --process Sys Pref
end tell -- System Events

关于applescripting 显示首选项面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37752288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com