Last active
April 29, 2021 14:28
-
-
Save timsutton/6141562 to your computer and use it in GitHub Desktop.
Very basic example to set a display device's default colorsync profile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "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