Reputation: 31
I’m attempting to write what I thought would be a simple script to change the color profile of my display. I’ve gotten as far as bringing up the Displays pref pane and choosing the Color tab, but have then run into real problems. My GUI scripting is sadly lacking and I cannot figure out how to choose a display profile. There are only two profiles showing in the scroll window ( “iMac” & “my Calibration 10-14” ). Ideally, I would like the script to toggle between the two profiles each time it is run. Here’s what I have so far:
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
Any help or suggestions would certainly be appreciated. I’m running OS 10.11.5
Upvotes: 3
Views: 1370
Reputation: 3105
You're not that far with this good start. the script should then found which row contains the profile 1 (iMac) and which row contains the profile 2 (your profile). if the row containing the profile 1 is selected, select the row containing profile 2.
That's what the script bellow does. You must adjust your 2 profiles in Prof1 and Prof2. the script uses "contains", so you don't have to set prof1/2 with complete value, just part of it is enough.
I also look for the case where one of the 2 profiles does not exists (then script does nothing).
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
Upvotes: 2