[英]Add keyboard shortcut
I want to make little app for my home. 我想为我的家制作小应用程序。 It should detect keyboard shortcut (for example: Cmd + C + 1 ) and send now selected text to my app (like automator service).
它会自动侦测键盘快捷键(例如:Cmd的 + C + 1),目前选定的文本发送到我的应用程序(如自动机服务)。
How can I do it? 我该怎么做? May be you can give tutorial link to me?
也许您可以给我教程链接?
I think you are wanting an Automator Action
. 我认为您要使用
Automator Action
。 In Xcode create an Application Plug-in
Automator Action
and post a notification to the NSDistributedNotificationCenter
在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;
}
You will need to implement an observer in your app 您将需要在您的应用中实现观察者
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(aSelector:) name:@"aName" object:nil];
If you include the Automator Action bundle in your app ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Contents/Library/Automator/
Automator should be able to find it. 如果您在应用程序中包含Automator Action捆绑包,则
${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Contents/Library/Automator/
Automator应该可以找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.