我想为我的家做一点应用。它应该检测键盘快捷键(例如: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应该能够找到它。