我已经确认这只发生在Lion.我发现了一个似乎是一个需要将窗口聚焦两次的错误,以便Finder通过脚本桥或AppleScript返回正确的结果.仅当从桌面或其他空间打开文件夹时才会发生这种情况.
这是复制的方法:
打开AppleScript编辑器并运行以下脚本:
tell application "Finder"
return selection
end tell
Run Code Online (Sandbox Code Playgroud)该脚本将仅返回桌面上文件夹的路径,而不是查找器窗口中的选定文件.
如果重新聚焦窗口,或再次单击该文件,一切都按预期工作,脚本返回正确的路径.
这似乎是Lion中的一个错误.Snow Leopard 100%的时间都会返回正确的路径.
我尝试了以下方法但没有成功:
所有人似乎都有同样的问题.
我错过了一些明显的东西,或者这真的是狮子的问题?
我需要在服务菜单中默认启用我创建的服务.
我为我的OS X应用程序(在Snow Leopard上运行)创建了一项服务.我已经像这样配置了Info.plist:
<key>NSServices</key>
<array>
<dict>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
<key>NSMessage</key>
<string>dropService</string>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Drop Service</string>
</dict>
<key>NSPortName</key>
<string>MyApp</string>
</dict>
</array>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我遵循以下其他步骤:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/introduction.html,一切似乎都正常.
我跑了命令:
/System/Library/CoreServices/pbs
Run Code Online (Sandbox Code Playgroud)
现在我的服务显示在"系统偏好设置 - >键盘 - >键盘快捷键 - >服务"下.所以系统知道它.但它不会显示在服务菜单中,除非我手动激活它.
当我尝试调试服务时,我收到以下消息:
/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices com.myapp.MyApp
Drop Service (com.myapp.MyApp) is disabled in the services menu and disabled in the context menu, by the standard Services policy.
Run Code Online (Sandbox Code Playgroud)
我不知道"标准服务政策"是什么,我在Apple开发者网站上找不到任何对此错误的引用.
我认为自动启用服务项是不可能的,但我已经确认某些应用程序会这样做(比如来自文化代码的东西)所以我知道它可以完成.
有任何想法吗?