Skip to content

Instantly share code, notes, and snippets.

@timsutton
Last active April 29, 2021 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timsutton/6141562 to your computer and use it in GitHub Desktop.
Save timsutton/6141562 to your computer and use it in GitHub Desktop.
Very basic example to set a display device's default colorsync profile.
#!/usr/bin/python
import objc
import Foundation
import Quartz
# replace with url-encoded path to an icc profile
URL_ENCODED_ICC_PATH = 'file:///Library/Application%20Support/Adobe/Color/Profiles/SMPTE-C.icc'
# stripped bridge metadata of all we need for this sample:
objc.parseBridgeSupport("""<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='1.0'>
<constant name='kColorSyncDeviceDefaultProfileID' type='^{__CFString=}'/>
<constant name='kColorSyncDisplayDeviceClass' type='^{__CFString=}'/>
<function name='CGDisplayCreateUUIDFromDisplayID'>
<arg type='I'/>
<retval already_retained='true' type='^{__CFUUID=}'/>
</function>
<function name='ColorSyncDeviceCopyDeviceInfo'>
<arg type='^{__CFString=}'/>
<arg type='^{__CFUUID=}'/>
<retval already_retained='true' type='^{__CFDictionary=}'/>
</function>
<function name='ColorSyncDeviceSetCustomProfiles'>
<arg type='^{__CFString=}'/>
<arg type='^{__CFUUID=}'/>
<arg type='^{__CFDictionary=}'/>
<retval type='B'/>
</function>
</signatures>
""", globals(), '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework')
main_display_id = Quartz.CGMainDisplayID()
display_uuid = CGDisplayCreateUUIDFromDisplayID(main_display_id)
print "Current device info:"
deviceInfo = ColorSyncDeviceCopyDeviceInfo(kColorSyncDisplayDeviceClass, display_uuid)
print deviceInfo
profile_url = Foundation.CFURLCreateWithString(None, URL_ENCODED_ICC_PATH, None)
# info on config dict required:
# /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework/Versions/A/Headers/ColorSyncProfile.h
# http://web.archiveorange.com/archive/print/YwdQZYJTswvvG79VTuyD
new_profile_dict = { kColorSyncDeviceDefaultProfileID: profile_url }
print "Setting profile..."
done = ColorSyncDeviceSetCustomProfiles(kColorSyncDisplayDeviceClass, display_uuid, new_profile_dict)
print "Succeeded: %s" % done
print
print "Current device info:"
deviceInfo = ColorSyncDeviceCopyDeviceInfo(kColorSyncDisplayDeviceClass, display_uuid)
print deviceInfo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment