如何使用swift或objective-c以编程方式更改macosx可可应用程序中的系统光标大小? [英] How to change the size of the system cursor in a macosx cocoa app programmatically using swift or objective-c?
问题描述
我尝试使用此代码设置其全局大小:
I've tried to set it's global size using this code:
-(void)setOption {
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];
NSLog(@"Cursor size set to %@", newdict);
}
我可以在NSLog看到它改变了它,但我不知道如何重新启动/重置系统光标,以便光标更改为指定的大小。
And I can see in the NSLog that it changed it but I don't know how to restart/reset the system cursor in order for the cursor to change to the specified size.
有人知道更好的方式来更改它的大小程序化或如何在默认更改后重新启动系统光标?
Does anybody know a better way to change it's size programmatically or how to restart the system cursor after the defaults change?
EDIT(关于重复):我的问题是唯一的,因为我不能使用applescript这就像在另一个话题提供的答案。此外,主题已在2013年创建,似乎过时。也许事情从那以后改变了一点。也许Swift可能是一个可行的解决方案。谁知道?所有这些参数清楚地表明这不是一个重复的问题。
EDIT(about duplication): My question is unique because I can't use applescript in resolving this like the answer provided in the other topic. Also the topic has been created in 2013, and seems outdated. Maybe things have changed a little since then. Also maybe Swift would be a viable solution for resolving this. Who knows? All these arguments make it clear that this is not a duplicate question.
推荐答案
警告。此代码不基于保存在偏好设置中的内容,因此将其合并:
Warning. This code is not based on what is saved in preferences so combine it:
float cursorScale = 2;
cursorScale = MAX(1, MIN(cursorScale,4));
int connectionID = CGSMainConnectionID();
CGSSetCursorScale(connectionID, cursorScale);
获得大小
CGSGetCursorScale(connectionID, &cursorScale);
,
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];
NSLog(@"Cursor size set to %@", newdict);
CREDITS: Alex Zielenski
这篇关于如何使用swift或objective-c以编程方式更改macosx可可应用程序中的系统光标大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!