[英]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.