服务菜单启动错误的应用程序包 [英] Services menu launches wrong application bundle

查看:86
本文介绍了服务菜单启动错误的应用程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经基于Apple文档中的"simpleEncrypt"示例实现了MacOS服务.我正在运行10.9和Xcode 6.2.

I have implemented a MacOS Service based on the 'simpleEncrypt' example from the Apple documentation. I'm running 10.9 and Xcode 6.2.

我可以构建应用程序捆绑包,将其复制到/Applications,运行一次,然后我的服务将按预期显示在其他应用程序的服务"菜单中.

I can build the application bundle, copy it to /Applications, run it once, and my service will appear in other applications' Services menu as expected.

如果我运行"pbs -dump_pboard",则应用程序包的正确路径如预期的那样显示为NSBundlePath.

If I run 'pbs -dump_pboard', the correct path to my application bundle appears as NSBundlePath, as expected.

但是,当我从服务"菜单中选择服务时,MacOS将启动我的应用程序的旧副本,该副本位于〜/Library/Developer/Xcode/Archives中.

However, when I select my service from a Services menu, MacOS will launch an old copy of my application that resides in ~/Library/Developer/Xcode/Archives.

如果删除该旧副本,它将从其他地方运行另一个副本.只有删除文件系统上与我的服务的NSPortName相同的CFBundleName的所有其他应用程序捆绑包之后,MacOS才能从/Applications启动正确的捆绑包.并且当它运行时,该服务也可以正常工作.

If I delete that old copy, it will run another copy from someplace else. Only after I delete every other application bundle on the filesystem that has the same CFBundleName as my service's NSPortName will MacOS launch the right one from /Applications. And when it does, the service works properly.

如何使MacOS可靠地为我的服务调用正确的应用程序捆绑包?

How can I get MacOS to reliably invoke the correct application bundle for my service?

推荐答案

在OS X中,应用程序已通过

In OS X, applications are registered with Launch Services, which is responsible for executing an application when requested, either by double-clicking on its app bundle, via spotlight, or in your case, running from the Services menu.

注册是自动进行的,例如,将应用程序复制到/Applications文件夹(不仅仅复制文件),甚至只是通过运行该进程即可.

Registration is automatic and happens, for example, when an application is copied to the /Applications folder (which does more than just copy the files) or even by just running the process.

运行带有-dump参数的lsregister命令可以查看已注册的应用程序列表.在OS X 10.10上,可能是这样的:-

The list of registered applications can be viewed by running the lsregister command with the -dump argument. On OS X 10.10, it would be this: -

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump

由于您具有同一应用程序的多个副本,因此它们的注册详细信息是相同的,因此Launch Services将不会更新其数据库,而只是执行与注册详细信息匹配的第一个看到的应用程序.

As you have multiple copies of the same application, their registration details are identical, so Launch Services will not update its database and simply executes the first seen application matching the registration details.

In the Apple docs, it suggests that you can either register the application in code with the functions LSRegisterFSRef and LSRegisterURL, using the inUpdate boolean parameter, or alternatively:

更新应用程序的修改时间,以确保将由自动注册实用程序对其进行更新

update the modification time of the application to ensure that it will be updated by the automatic registration utilities

我希望您仍然必须直接运行该应用程序,以确保Launch Services更新其数据库.如果是捆绑软件,则可以直接导航到应用程序的二进制文件.以Caculator.app为例,您将执行:-

I expect you'll still have to run the application directly, to ensure Launch Services updates its database. In the case of a bundle, you can navigate directly to the application's binary. Using Caculator.app as an example you'd execute:-

/Applications/Calculator.app/Contents/MacOS/Calculator

我发现的另一个选项是通过增加版本号或更确切地说通过更改其CFBundleIdentifier来更新应用程序的Info.plist.

Another option I've found is to update the application's Info.plist by incrementing the version number, or more radically, changing its CFBundleIdentifier.

这篇关于服务菜单启动错误的应用程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆