How to programmatically change cursor size on Mac

I would like to be able to set the system preference for the cursor size (as shown in the accessibility settings) on the Mac from my program, and then set it back after the program terminates.

Is there a way to set the size of the cursor (in particular) or system settings in general from the application?

+5
source share
1 answer

Firstly, if you are just trying to get a larger cursor when the cursor points to your window / view / widget, you are talking about it wrong. Read the Introduction to Cursor Manager carefully .

-, , , , . , . - ( , ), . , ? . ( , Apple App Store, .)

-, , , . , . , , , , , ( ), , .

, ...


. , , . "" com.apple.universalaccess. - mouseDriverCursorSize.

, bash:

defaults write com.apple.universalaccess mouseDriverCursorSize 4.0

ObjC, - (untested):

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *olddict = [defaults persistentDomainForName:@"com.apple.universalaccess"];
NSMutableDictionary *newdict = [olddict mutableCopy];
[newdict setObject:@4.0 forKey:@"mouseDriverCursorSize"];
[defaults setPersistentDomain:newdict forName:@"com.apple.universalaccess"];
[defaults synchronize]

, , , ? , " " - , , , .

, , . . , , , , . :

, CGSShowCursor , , , . , CGSGetGlobalCursorData , , .

, CGSPrivate, , , . , , - (iTerm2 ) Apple , 25% , 75% ( , 25%, , , ).

OS X, - GUI :

  • , .
  • Xcode 4.4 , "Xcode", "Open Developer Tool", "".
  • "" "Mac OS X | All", "System Trace".
  • "" " ".
  • "" , .
  • .
  • "" , .
  • , , , .

, syscall ; , , mach Window Server. , , . , , , -, UACursorSetScale UniversalAccessCore, UAPreferencesSetValue /System/Library/PrivateFrameworks/UniversalAccess.framework/Versions/A/Libraries/libUAPreferences.dylib, , , , CFPreferencesSetValue CFNotificationCenterPostNotification. , ? , Xcode/gdb/lldb , . , UAPreferencesSetValue ( , , CFPreferencesSetValue).

: "UniversalAccessDomainMouseSettingsDidChangeNotification" nil object a userInfo , @{@"mouseDriverCursorSize": @1.8327533, @"pid": @12345}, NSUserDefaults . , UAPreferencesSetValue, -, , CFPreferencesSetValue, , CFNotificationCenterPostNotification, , , , , .

, . , , .


. " " , , , ?

(. " " , " ", Google, , ), , , .

, -, , , . , AppleScript, , :

tell application "System Preferences"
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
    set theSlider to slider "Cursor Size:" of group 1 of window 1 of application process "System Preferences"
    set stash to value of theSlider
    set value of theSlider to 4.0
    stash
end tell

ObjC NSAppleScript - , , ScriptingBridge, Appscript - , - .

+10

All Articles