Choose Display Profile

So I’ve been searching high and low for a way for users to select an appropriate monitor profile when they log into the system. Based on some suggestions in another thread (I can’t find the source at the moment on MacScripter, but I’ll post it later on when and if I’m able to find it), but apparently Apple has removed the capability for Image Events to set a profile to a display. The following example seemed to have worked under Leopard, but no longer works under Snow Leopard.

tell application "Image Events"
	launch
	tell displays to set {cnt, dName, sProfiles} to {count it, name, display profile}
	set allProfiles to name of profiles
end tell

repeat with i from 1 to cnt
	set newProfile to choose from list allProfiles with prompt "Choose profile for display " & i default items (name of item i of sProfiles)
	if newProfile is not false then
		set newProfile to item 1 of newProfile
		tell application "Image Events" to set profile of display i to profile newProfile
	end if
end repeat

I know I’m off when it comes to the “tell application “Image Events” to set profile of display i to profile newProfile”

The set function apparently no longer works because display is read only. What I’m looking for is a workaround that will still allow me to choose a display profile and then apply it to each monitor connected. Any help would be much appreciated.

A quick search thought me that the display profile of a display is set with the application ColorSyncScripting. (Google search “display profile applescript”, click first link.) Then I looked at the dictionary of Image Events, searched for the class profile and saw the location property. I coerced it in an alias and voila, the script is ready. Though it doesn’t work for all profiles and some displays. E.g. the Black & White profile doesn’t work for Samsung Syncmaster :slight_smile:

Script:

tell application "Image Events"
	launch
	tell displays to set {cnt, dName, sProfiles} to {count it, name, display profile}
	set allProfiles to name of profiles
end tell

repeat with i from 1 to cnt
	set newProfile to choose from list allProfiles with prompt "Choose profile for display " & i default items (name of item i of sProfiles)
	if newProfile is not false then
		set newProfile to item 1 of newProfile
		--tell application "Image Events" to set display profile of display i to profile newProfile
		
		tell application "Image Events" to set profileAlias to location of profile newProfile
		set profileAlias to profileAlias as alias
		
		tell application "ColorSyncScripting"
			set display profile of display i to profileAlias
		end tell
	end if
end repeat

Hope it helps,
ief2

I think you might have to do it in the preference pane:


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

Unfortunately, ColorSyncScripting no longer works under Snow Leopard. You must be working with Tiger or Leopard.

I work with Leopard indeed

I might just go with the systems preferences approach. It may not be as clean, but it does essentially the same thing.

Er, a bit new to all this, so what does Adam’s “do your stuff” consist of? How do you actually set a color profile once you’re on the Color pane?

Oh, and how did you know what to do? I get as far as “pane” by looking at the System Preferences dictionary but then I get stuck.

Thanks!

After you have displayed the pane, you can go on with GUI scripting. For this look at the “System Events” dictionary’s Processes Suite. Here’s an example of GUI scripting with iTunes:

tell application "System Events" to tell process "iTunes"
	activate
	-- activate Music Playlist
	tell window 1 to tell splitter group 1 to tell splitter group 1 to ¬
		tell scroll area 1 to tell outline 1 to select row 2
	
	
	tell window 1 -- main window
		click button 9 -- list
		delay 3
		click button 10 -- album covers
		delay 3
		click button 11 -- cover flow
	end tell
end tell

This script is tested with iTunes 9.1

Hope it helps,
ief2

PS: A good tool for GUI scripting is PreFab’s UI Browser

This seems to do the trick:

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")
	tell application "System Events"
		tell process "System Preferences"
			select row 2 of table 1 of scroll area 1 of group 1 of tab group 1 of window "Color LCD"
		end tell
	end tell
	quit
end tell

Anything I’m missing? Thanks!

hello people.

I have a Spyder3 calibrator, and I change the display profile and brightness throughout the day as the ambient light changes. I wrote a script to set the display profile and brightness in the days of Leopard which worked until Snow Leopard happened and the script broke. but…

based on that script and what I’ve read here and in other places, I edited my script and it works again. here it is. I hope it is helpful.

(Note. I use Script Debugger and take advantage of its Libraries function; i.e., I have 5 scripts, one for each ambient level, all of them single-line scripts calling the configureTheDisplay() function embedded via the Libraries function. You could probably do something similar in Script Editor by using the Load Script function.)


-- Note 1. theProfilesName is the name of the profile as seen in the Displays pref panel, not its alias.
-- Note 2. brightnessValue is a Number. do not wrap its value in quotation marks.
configureTheDisplay("Spyder3Pro Very Low", 13 / 64)

to configureTheDisplay(theProfilesName, brightnessValue)
	tell application "System Events"
		if not UI elements enabled then
			DisplayAssistanceInstructions() of me
			return
		end if
		
		openDisplaysPrefPane() of me
		tell process "System Preferences"
			-- set the brightness
			-- make sure the Display panel is on.
			click radio button "Display" of tab group 1 of window 1
			set slider 1's value of group 2 of tab group 1 of window 1 to brightnessValue
			
			-- set the ColorSync Profile
			click radio button "Color" of tab group 1 of window 1
			select (first row of table of scroll area of group of tab group 1 of window 1 where its first static text's name is theProfilesName)
		end tell
		quitPrefs() of me
	end tell
	return
end configureTheDisplay

to DisplayAssistanceInstructions()
	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.universalaccess"
		display alert "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
	end tell
end DisplayAssistanceInstructions

to openDisplaysPrefPane()
	tell application "System Preferences"
		set current pane to pane "Displays"
	end tell
end openDisplaysPrefPane

to quitPrefs()
	quit application "System Preferences"
end quitPrefs

I use the following script to get the Display Brightness value after I’ve done a calibration, which I then plug back into the script above.


tell application "System Preferences" to ¬
	set current pane to pane "Displays"

tell application "System Events"
	tell tab group 1 of window 1 of process "System Preferences"
		click radio button "Display"
		tell slider 1 of group 2
			set v_true to value
		end tell
	end tell
end tell
quit application "System Preferences"

set v to v_true * 64 as integer
if v mod 4 = 0 then
	set v to ((v / 4 as integer) & "/16") as string
else if v mod 2 = 0 then
	set v to ((v / 2 as integer) & "/32") as string
else
	set v to (v & "/64") as string
end if
display alert "Current Display Brightness: " & v & " (" & v_true & ")" buttons "OK"