Show folder's contents in finder using Swift
Use the selectFile
method and pass nil
as first argument and the path to the folder to be shown as second argument.
NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: "/Users/")
Open directory in finder?
You should use FileManager urls for applicationDirectory at the systemDomainMask and append your path component to the url returned. Then all you need is use open method and pass your directory url:
if let inspirationsDirectory = FileManager.default.urls(for: .applicationDirectory, in: .systemDomainMask).first?.appendingPathComponent("Inspirations", isDirectory: true){
NSWorkspace.shared.open(inspirationsDirectory)
}
Launch Finder window with specific files selected
Objective-C version:
NSArray *fileURLs = [NSArray arrayWithObjects:fileURL1, /* ... */ nil];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
How do I programmatically open a folder in the Finder without selecting anything?
It suffices to ask the workspace to open the folder as a file, because the Finder is the default app for folders. For example:
NSWorkspace.shared.open(
URL(
fileURLWithPath: "/System/Library/CoreServices",
isDirectory: true
)
)
(The isDirectory
parameter is optional but passing it saves a system call.)
How can I display my App documents in the Files app for iPhone
If you would like to expose your App document files inside Apple's Files App you need to include the "Supports Document Browser"
key in your info plist file and set it to YES:
Created Group folder is not visible in show in finder on xcode
No. You have to track (create) the folders both in xocde and in finder manually.
You can create folder in finder and then can import that folder in xcode.
The folder you make in xcode is identical to the finder.
So, the folder that you will make in finder, will be the original tree structure for your project.
Related Topics
How to Open File Dialog with Swiftui on Platform "Uikit for MAC"
How to Make Apple Sign in Revoke Token Post Request
What Is the "@Exported" Attribute in Swift
How to Resolve This Build Issue - Cannot Assign to Property: 'Date' Is a Get Only Property
Firebase Sign Out Not Working in Swift
Macos/Swift Capture Audio with Avcapturesession
Why Can't I Change Variables in a Protocol Extension Where Self Is a Class
Subclass of Gkgraphnode Costtonode Method Never Getting Called
Why Can You Assign Non-Optional Values to Optional Types in Swift
How to Utilize Nslock to Prevent a Function from Firing Twice
Detailed Instruction on Use of Nsopenpanel
Does Kotlin Has Extension Class to Interface Like Swift
Translucent Status Bar with No Navigation Bar
Swift 3:Fatal Error: Double Value Cannot Be Converted to Int Because It Is Either Infinite or Nan
Hstack with Sf Symbols Image Not Aligned Centered
Adding a Search Bar to Navigationview in Swiftui
How to Detect Switch Between MACos Default & Dark Mode Using Swift 3