簡體   English   中英

如何查詢 Finder NSURL?

[英]How do I query for Finder NSURL?

在任何 macOS 系統上確定 Finder.app 的 NSURL 的正確方法是什么?

這是上下文。 我的應用程序中有以下代碼行:

NSWorkspace.shared.openFile(pathToTempFile, withApplication: "Finder")

這會導致 Swift 編譯器警告我:

'openFile(_:withApplication:)' was deprecated in macOS 11.0: Use -[NSWorkspace openURLs:withApplicationAtURL:configuration:completionHandler:] instead.

切換到較新 API 的問題是我不知道如何確定 Finder 的withApplicationAtURL參數。 顯然,我可以在自己的系統上找到 Finder 的路徑,但我不知道這是否是所有 macOS 系統的正確路徑,更不用說未來版本的 macOS。 我只是硬編碼對我有用的東西。

我在 Apple 文檔中或從網絡搜索中找不到任何可以為我提供該系統上 Finder.app 的 URL 的 API。 我能做些什么?

NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.Finder")
// $R1: Foundation.URL? = "file:///System/Library/CoreServices/Finder.app/"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM