繁体   English   中英

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

[英]Force a *new* Finder window to open programmatically

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

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

我试过NSWorkspace.shared.selectFile()NSWorkspace.shared.open() ,以及通过 shell 脚本运行open 都有相同的效果。

有没有办法强制 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

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

只需调用这个:

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

在 Swift 中应该是这样的:

NSWorkspace.shared.activateFileViewerSelecting([url]) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM