2016-06-10 54 views
0

我试图写我认为会是一个简单的脚本来更改我的显示器的颜色配置文件。我已经尽可能地调出了显示器前面板并选择了颜色标签,但是却遇到了真正的问题。我的GUI脚本是可悲的缺乏,我不知道如何选择显示配置文件。滚动窗口中只显示两个配置文件(“iMac”&“我的校准10-14”)。理想情况下,我希望脚本在每次运行时在两个配置文件之间切换。这是我到目前为止:applescripting显示首选项窗格

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 

任何帮助或建议肯定会感激。我正在运行操作系统10.11.5

回答

0

在这个良好的开端中,你并不是那么遥远。该脚本应该找到哪一行包含配置文件1(iMac),哪一行包含配置文件2(您的配置文件)。 如果选择包含配置文件1的行,请选择包含配置文件2的行。

这就是脚本的风格。您必须在Prof1和Prof2中调整您的2个配置文件。该脚本使用“包含”,因此您不必设置prof1/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 
+0

非常感谢@pbell,不幸的是,这是行不通的。以下是我在运行脚本时得到的内容:错误“系统事件发生错误:无法获取应用程序进程窗口1的选项卡组1”系统偏好设置\“。索引无效。编号-1719从应用程序进程“系统首选项”的窗口1的选项卡组1中输入 – Eileen

+0

它正在处理我的系统imac27(10.11.5)。如果你有相同的版本,你应该有相同的界面。我怀疑这可能是你的硬件延迟。尝试在“设置Prof1”之前添加一行“delay 1”......这会让Mac有一段时间打开预设窗格。 – pbell

+0

它现在工作完美!我只做了改变,在“告诉前窗口的标签组1的滚动区域1的表”行之前添加了“延迟0.5”。感谢您的帮助! – Eileen

相关问题