2

I am creating a software on Mac and I would like to change the value of an IORegistryEntry. I can view it on the IORegistryExplorer, but I can't edit it. So it's my understanding that I have to edit it via code. Here is my code:

CFMutableDictionaryRef matchingDict = IOServiceNameMatching("AppleUSBMultitouchDriver");
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
if(service) {
 CFStringRef manufacturer = IORegistryEntryCreateCFProperty(service, CFSTR("Manufacturer"), kCFAllocatorDefault,0);
 NSLog(@"%@", (NSString*)manufacturer);
 kern_return_t err = IORegistryEntrySetCFProperty(service, CFSTR("Manufacturer"), CFSTR("test"));
 NSLog(@"error = %d", err);
}

This will output

2010-04-10 16:09:09.015 Test[41548:a0f] Apple Inc.
2010-04-10 16:09:09.015 Test[41548:a0f] error = 0

But after I check the value in the IORegistryExplorer, it still doesn't change. Does anybody have any suggestions?

Thank you

Machavity
  • 30,841
  • 27
  • 92
  • 100
yangumi
  • 21
  • 1
  • 3

3 Answers3

1

In order for this to be possible, usually the driver for the particular hardware you're changing has to implement setProperties() (in IOKit) that makes this change for you.

It's unlikely that Apple will implement setProperty() in their AppleUSBMultitouchDriver in a way that allows you to change the manufacturer name. They want to specify what kind of fruit they are. ;)

WhirlWind
  • 13,974
  • 3
  • 42
  • 42
  • Thank you very much for your answer. Actually, I don't want to change the manufacturer name. That's just for the example :-) I want to change the value of "trackpadUserPreferences." Apparently, Apple's Trackpad preference pane can do this, but I don't know how it does. Could you tell me how I can obtain the object that I can call the setProperty method, please? I looked at the binary of /System/Library/Extensions/AppleUSBMultitouch.kext/Contents/MacOS/AppleUSBMultitouch and found a string "AppleUSBMultitouchDriver::setProperty" but I don't know if this is related to this in any way. – yangumi Apr 10 '10 at 23:27
  • I don't know -- I'd run System Preferences in a debugger and have it break on that call to see how it's calling into the registry functions. – WhirlWind Apr 10 '10 at 23:36
0

Use IOConnectSetCFProperties instead of IORegistryEntrySetCFProperty. Pass it a dictionary with the settings you want to set.

For example to turn off three finger swipe to navigate, call it with a dictionary containing { TrackpadThreeFingerSwipe = 0; }

Ken Aspeslagh
  • 11,484
  • 2
  • 36
  • 42
  • Thank you very much for your help. I tried your suggestion, but it still doesn't work :-( I've posted my actual code below. – yangumi Apr 11 '10 at 19:05
0

This is example how to change trackpad settings properly. Trackpad.prefpane do exactly this, but also save this setting somewhere in defaults (if you will not find out where exactly, ask here about it).

P.S. getEVSHandle() may be found in MachineSettings.framework.

P.P.S. Checked only on 10.5 & 10.6.

NSInteger zero = 0, one = 1;

CFNumberRef _numberWith0 = CFNumberCreate(kCFAllocatorDefault, kCFNumberNSIntegerType, &zero);
CFNumberRef _numberWith1 = CFNumberCreate(kCFAllocatorDefault, kCFNumberNSIntegerType, &one);

CFMutableDictionaryRef propertyDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, NULL, NULL);

CFDictionarySetValue(propertyDict, @"TrackpadThreeFingerSwipe", flag ? _numberWith1 : _numberWith0);

io_connect_t connect = getEVSHandle();

if (!connect)
{
// error
}

kern_return_t status = IOConnectSetCFProperties(connect, propertyDict);

if (status != KERN_SUCCESS)
{
//error
}

CFRelease(propertyDict);
J59
  • 1
  • I found this through google, and I am trying to do a similar thing. However `getEVSHandle` is not defined for me. How do I get this in a simple C program? – user826955 Oct 10 '19 at 11:55