I'm trying to programmatically launch an OS X Finder window from an Xcode project. I need the window to open to a specific folder and have specific files within that folder automatically selected.
This is similar to the "Show in Finder" functionality used in Xcode and related apps.
Does anyone know how to do this in either Objective-C, Swift, AppleScript, or Finder command-line parameters?
In the Finder on your Mac, choose Go > Go to Folder. Start typing the folder's pathname (for example, /Library/Fonts/ or ~/Pictures/). As you type, matching folders appear. Type a slash (/) at the beginning of a pathname to indicate that the starting point is the top level of your computer's folder structure.
On the Finder Preferences dialog box, click General on the toolbar at the top. Click on the New Finder windows show drop-down menu. A list of predefined options displays. If you want to open one of these locations, select the option you want.
Resize the sidebar: Drag the right side of the divider bar to the right or left. Change what's in the sidebar: Choose Finder > Preferences, click Sidebar, then select or deselect items. Rearrange items in the sidebar: Drag an item to a new location.
Do one of the following: Go to the menu bar and select File > New Finder Window. Right-click Finder in your Dock and select New Finder Window from the shortcut menu. Use the keyboard shortcut Command + N.
Objective-C version:
NSArray *fileURLs = [NSArray arrayWithObjects:fileURL1, /* ... */ nil]; [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
$ open -R <path-to-reveal>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With