NSOpenPanel Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Declared in
NSOpenPanel.h
Companion guides
Related sample code

Overview

The NSOpenPanel class provides the Open panel for the Cocoa user interface. Applications use the Open panel as a convenient way to query the user for the name of a file to open.

In a sandboxed environment, Open panels are drawn in a separate process by the powerbox, not by AppKit itself. When the user chooses a file to open, OS X adds that file to the app’s sandbox.

Tasks

Creating Panels

Configuring Panels

Running Panels

Accessing User Selection

Class Methods

openPanel

Creates and returns a NSOpenPanel object.

+ (NSOpenPanel *)openPanel
Return Value

The initialized Open panel.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h

Instance Methods

allowsMultipleSelection

Returns whether the panel’s browser allows the user to open multiple files (and directories) at a time.

- (BOOL)allowsMultipleSelection
Return Value

YES if the panel’s browser allows multiple selection; otherwise, NO.

Discussion

If multiple files or directories are allowed, then the filename method—inherited from NSSavePanel—returns a non-nil value only if one and only one file is selected. By contrast, NSOpenPanel’s URLs method always returns the URLs of the selected files, even if only one file is selected.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h

canChooseDirectories

Returns whether the panel allows the user to choose directories to open.

- (BOOL)canChooseDirectories
Return Value

YES if the panel allows the user to choose directories; otherwise, NO.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h

canChooseFiles

Returns whether the panel allows the user to choose files to open.

- (BOOL)canChooseFiles
Return Value

YES if the panel allows the user to choose files; otherwise, NO.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h

resolvesAliases

Returns whether the panel resolves aliases.

- (BOOL)resolvesAliases
Return Value

YES if the panel resolves aliases; otherwise, NO.

Discussion

If YES, the effect is that dropping an alias on the panel or asking for filenames or URLs returns the resolved aliases. The default is YES.

Availability
  • Available in OS X v10.1 and later.
Declared In
NSOpenPanel.h

setAllowsMultipleSelection:

Sets whether the user can select multiple files (and directories) at one time for opening.

- (void)setAllowsMultipleSelection:(BOOL)flag
Parameters
flag

If YES, the panel’s browser allows multiple selection; if NO, it does not.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h

setCanChooseDirectories:

Sets whether the user can select directories in the panel’s browser.

- (void)setCanChooseDirectories:(BOOL)flag
Parameters
flag

If YES, the panel allows the user to choose directories; if NO, it does not.

Discussion

When a directory is selected, the OK button is enabled only if flag is YES.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h

setCanChooseFiles:

Sets whether the user can select files in the panel’s browser.

- (void)setCanChooseFiles:(BOOL)flag
Parameters
flag

If YES, the panel allows the user to choose files; if NO, it does not.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h

setResolvesAliases:

Sets whether the panel resolves aliases.

- (void)setResolvesAliases:(BOOL)resolvesAliases
Parameters
resolvesAliases

If YES, the panel resolves aliases; if NO, it does not.

Discussion

If YES, the effect is that dropping an alias on the panel or asking for filenames or URLs returns the resolved aliases. Set this value to NO to allow selection of aliases without resolving.

Availability
  • Available in OS X v10.1 and later.
Declared In
NSOpenPanel.h

URLs

Returns an array containing the absolute paths of the selected files and directories as URLs.

- (NSArray *)URLs
Return Value

The array of URLs.

Discussion

If multiple selections aren’t allowed, the array contains a single name.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSOpenPanel.h