I need to programmatically change the values of the Caps Lock, Control, Option and Command keys in "System Preferences > Keyboard > Modifier Keys..."
I dont want to use AppleScript.
Could someone point me in the right direction?
I need to programmatically change the values of the Caps Lock, Control, Option and Command keys in "System Preferences > Keyboard > Modifier Keys..."
I dont want to use AppleScript.
Could someone point me in the right direction?
Here is apple script capsLockOff.scpt:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
tell application process "System Preferences"
get properties
click button "Modifier Keys…" of tab group 1 of window "Keyboard"
tell sheet 1 of window "Keyboard"
click pop up button 4
click menu item "No Action" of menu 1 of pop up button 4
delay 1
click button "OK"
end tell
end tell
end tell
tell application "System Preferences" to quit
Following is cocoa code to call above script. Hope this will help
-(void)runAppleScript{
NSString *fileName = @"capsLockOff";
NSString* path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];
[appleScript release];
}
See my answer in Does anyone know where OSX stores the settings in System Preferences > Keyboard > Modifier Keys?. The setting is in ~/Library/Preferences/ByHost/.GlobalPreferences.<UUID>.plist
.
As I suggested in comments :
I think if you can do it through AppleScript, then you can execute same commands via cocoa code ;)
You can refer this document to do so: Using AppleScript Scripts in Cocoa Applications
Hope this helps :)