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

发布于 2024-12-20 12:23:23 字数 814 浏览 4 评论 0原文

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

复制方法如下:

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

    告诉应用程序“Finder”
        返回选择
    结束告诉
    

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

如果您重新聚焦窗口,或再次单击该文件,一切都会按预期运行,并且脚本会返回正确的路径。

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

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

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

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

我是否遗漏了一些明显的东西,或者这确实是 Lion 的问题吗?

I've confirmed that this is only happening in Lion. I've uncovered what appears to be a bug where you need to focus a window twice in order for Finder to return the correct result over the scripting bridge or AppleScript. This only happens when opening a folder from the desktop or another space.

Here's how to duplicate:

  1. Close, hide or minimize all windows until the desktop is showing.
  2. Open any folder on the desktop, a new finder window will appear. Select any file in that finder window by clicking on it once.
  3. Open your AppleScript Editor and run the following script:

    tell application "Finder"
        return selection
    end tell
    

The script will return only the path to the folder on the desktop, not the selected file in the finder window.

If you refocus the window, or click on the file again, everything works as expected and the script returns the correct path.

This seems like a bug in Lion. Snow Leopard returns the correct path 100% of the time.

I've tried the following methods with no success:

  1. Using the scripting bridge and https://github.com/davedelong/BetterInfo/blob/master/Finder.h
  2. Using "System Events" apple script to click "Edit"->"Copy"
  3. Using AppleScript to get the current selection from the finder.

All seem to have have the same issue.

Am I missing something obvious or is this truly a problem with Lion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2024-12-27 12:23:23

哇,我可以确认(至少通过 applescript)你所描述的大部分内容。我收到一个空列表返回,甚至没有您提到的桌面路径。我正在使用 applescript 菜单中的脚本对此进行测试。我可以从新的 Finder 窗口中进行选择的唯一方法是这样的......

tell application "System Events" to activate
tell application "Finder"
    activate
    set a to (get selection) as text
    display dialog a
end tell

Wow, I can confirm (at least through applescript) most of what you describe. I was getting an empty list returned, not even the desktop path you mention. I was testing this using a script in the applescript menu. The only way I could get the selection from a fresh Finder window was like this...

tell application "System Events" to activate
tell application "Finder"
    activate
    set a to (get selection) as text
    display dialog a
end tell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文