小编Lev*_*ink的帖子

在OS X Lion中,向Finder询问当前选择,返回错误的文件

我已经确认这只发生在Lion.我发现了一个似乎是一个需要将窗口聚焦两次的错误,以便Finder通过脚本桥或AppleScript返回正确的结果.仅当从桌面或其他空间打开文件夹时才会发生这种情况.

这是复制的方法:

  1. 关闭,隐藏或最小化所有窗口,直到桌面显示.
  2. 打开桌面上的任何文件夹,将出现一个新的查找程序窗口.通过单击一次选择该查找程序窗口中的任何文件.
  3. 打开AppleScript编辑器并运行以下脚本:

    tell application "Finder"
        return selection
    end tell
    
    Run Code Online (Sandbox Code Playgroud)

该脚本将返回桌面上文件夹的路径,而不是查找器窗口中的选定文件.

如果重新聚焦窗口,或再次单击该文件,一切都按预期工作,脚本返回正确的路径.

这似乎是Lion中的一个错误.Snow Leopard 100%的时间都会返回正确的路径.

我尝试了以下方法但没有成功:

  1. 使用脚本桥和https://github.com/davedelong/BetterInfo/blob/master/Finder.h
  2. 使用"系统事件"苹果脚本单击"编辑" - >"复制"
  3. 使用AppleScript从取景器中获取当前选择.

所有人似乎都有同样的问题.

我错过了一些明显的东西,或者这真的是狮子的问题?

macos applescript objective-c osx-lion

6
推荐指数
1
解决办法
830
查看次数

如何在OS X服务菜单中自动激活项目

我需要在服务菜单中默认启用我创建的服务.

我为我的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开发者网站上找不到任何对此错误的引用.

我认为自动启用服务项是不可能的,但我已经确认某些应用程序会这样做(比如来自文化代码的东西)所以我知道它可以完成.

有任何想法吗?

macos cocoa objective-c

3
推荐指数
2
解决办法
3772
查看次数

标签 统计

macos ×2

objective-c ×2

applescript ×1

cocoa ×1

osx-lion ×1