Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 使用Alt NSKEYEQUALINE命令注册NSService_Cocoa - Fatal编程技术网

Cocoa 使用Alt NSKEYEQUALINE命令注册NSService

Cocoa 使用Alt NSKEYEQUALINE命令注册NSService,cocoa,Cocoa,我的应用程序提供全局服务。我想用命令和alt键组合安装该服务。我现在所做的事情不太容易出错,而且调试起来也很困难,因为我看不到发生了什么: inside Info.plist: <key>NSServices</key> <array> <dict> <key>NSSendTypes</key> <array> <string></string> <

我的应用程序提供全局服务。我想用命令和alt键组合安装该服务。我现在所做的事情不太容易出错,而且调试起来也很困难,因为我看不到发生了什么:

inside Info.plist:
 <key>NSServices</key>
 <array>
  <dict>
   <key>NSSendTypes</key>
   <array>
    <string></string>
   </array>
   <key>NSReturnTypes</key>
   <array>
    <string></string>
   </array>
   <key>NSMenuItem</key>
   <dict>
    <key>default</key>
    <string>Go To Window in ${PRODUCT_NAME}</string>
   </dict>
   <key>NSMessage</key>
   <string>bringZFToForegroundZoomOut</string>
   <key>NSPortName</key>
   <string>com.raskinformac.${PRODUCT_NAME:identifier}</string>
  </dict>
 </array>
以及更改服务:

// once installed, its's a bit tricky to set new ones (works only in RELEASE somehow?)
// quit finder
// open "~/Library/Preferences/pbs.plist" and remove ch.ana.Zoom - Reveal Window in Zoom - bringZFToForegroundZoomOut inside NSServicesStatus and save
// start app
// /System/Library/CoreServices/pbs -dump_pboard (to see if it hat actually done what we wanted, might be empty)
// /System/Library/CoreServices/pbs  (to add the new services)
// /System/Library/CoreServices/pbs -dump_pboard  (see new linking)
// and then /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder  -NSDebugServices MY.APP.IDENTIFIER  to restart finder

所以我的问题是:有没有更简单的方法来启用带有cmd选项键的服务?如果是,我很乐意在我的软件中实现它。

您可以尝试将您的密钥等效字符串设置为“~”作为服务字典中的
NSKeyEquivalent
的值。声明必须是单个字符,但我认为值得尝试全键等效字符串。

请记住,与NSMenuItem一样,它必须包装在字典中:

<key>NSKeyEquivalent</key>
<dict>
    <key>default</key>
    <string>~r</string>
</dict>
nskey等效
违约
~r
(我省略了“@”;如果没有它就无法工作,您可以尝试使用它。)

如果它真的有效,我建议不要使用文档


苹果可能希望所有服务都使用其中一种⌘-某物或⇧⌘-某个键等价,为菜单项和全局热键保留其他修改器。因此,当我尝试上述方法时,如果它不起作用,我也不会感到太惊讶。

刚刚想出了如何测试和调试整个过程。而不是/System/Library/CoreServices/pbs和NSUpdateDynamicServices,永远不知道我的应用程序现在到底有什么,上次缓存了什么:*在mac上创建来宾帐户*构建二进制文件并设置所有信息。plist*登录来宾*查看服务菜单*启动应用程序*再次查看服务菜单*决定是否好的,记住遗漏了什么*注销,OS X会清理所有东西*下次登录时:拥有一台mac电脑,因为它在Peter之前从未知道任何事情,非常感谢你的回答。我尝试了~和@~,但都没有成功。但我发现了问题:看看我的答案。
<key>NSMenuItem</key>
       <dict>
        <key>default</key>
        <string>Go To Window in ${PRODUCT_NAME}</string>
       </dict>
<key>NSMenuItem</key>
       <dict>
        <key>default</key>
        <string>Go To Window in ${PRODUCT_NAME}</string>
       </dict>
NSString *appServiceName = @"Go To Window in ${PRODUCT_NAME}"
CFStringRef serviceStatusName = (CFStringRef)[NSString stringWithFormat:@"%@ - %@ - %@", appIdentifier, appServiceName, methodNameForService];