2016-06-10 52 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

相關問題