Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Finder window with specific files selected

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?

like image 447
simon.d Avatar asked Oct 04 '11 19:10

simon.d


People also ask

How do I open a specific folder in Finder on Mac?

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.

How do I change what opens in Finder on Mac?

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.

How do I customize Finder window on Mac?

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.

How do I open multiple Finder windows on a Mac?

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.


2 Answers

Objective-C version:

NSArray *fileURLs = [NSArray arrayWithObjects:fileURL1, /* ... */ nil]; [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs]; 
like image 187
Wevah Avatar answered Oct 02 '22 11:10

Wevah


$ open -R <path-to-reveal> 
like image 22
Matt McClure Avatar answered Oct 02 '22 12:10

Matt McClure