强制*新* Finder window 以编程方式打开

Force a *new* Finder window to open programmatically

我正在实施“在 Finder 中显示”功能,但重要的是 Finder window 应该始终出现 - 无论 windows 已经开放。

Finder 似乎总是喜欢激活共享同一目录的现有 window;在某些情况下,它甚至会重新导航现有的 window 以突出显示请求的路径。

我已经尝试 NSWorkspace.shared.selectFile()NSWorkspace.shared.open(),以及 运行 open 通过 shell 脚本。都是一样的效果。

有没有办法强制 Finder 打开新的 windows - 即使路径重复?

我试过这个 (AppleScript):

tell application "Finder"
    set f to document file "eStmt_2021-01-14.pdf" of folder "Downloads" of folder "mattmobile" of folder "Users" of startup disk
    set fol to folder "Downloads" of folder "mattmobile" of folder "Users" of startup disk
    activate
    set w to make new Finder window
    set target of w to fol
    select f
end tell

工作正常:每次运行时,它都会创建一个 new window 并显示并选择 window 中的目标文件。

就叫这个:

[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[url]];

在Swift中应该是这样的:

NSWorkspace.shared.activateFileViewerSelecting([url])