[英]Add keyboard shortcut
我想为我的家制作小应用程序。 它会自动侦测键盘快捷键(例如:Cmd的 + C + 1),目前选定的文本发送到我的应用程序(如自动机服务)。
我该怎么做? 也许您可以给我教程链接?
我认为您要使用Automator Action
。 在Xcode中,创建一个Application Plug-in
Automator Action
并将通知发布到NSDistributedNotificationCenter
- (id)runWithInput:(id)input fromAction:(AMAction *)anAction error:(NSDictionary **)errorInfo
{
NSDistributedNotificationCenter *dc = [NSDistributedNotificationCenter defaultCenter];
[dc postNotificationName:@"aName" object:@"anObject"
userInfo:[NSDictionary dictionaryWithObject:input
forKey:@"aKey"]];
return input;
}
您将需要在您的应用中实现观察者
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(aSelector:) name:@"aName" object:nil];
如果您在应用程序中包含Automator Action捆绑包,则${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Contents/Library/Automator/
Automator应该可以找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.