HSUIFilePicker

A file or directory selection dialog

Shows a standard macOS open panel for selecting files or directories. Supports multiple selection, file type filtering, and more.

Examples

File Picker

hs.ui.filePicker()
    .message("Choose a file to open")
    .allowedFileTypes(["txt", "md", "js"])
    .onSelection((path) => {
        if (path) {
            print("Selected: " + path);
        } else {
            print("User cancelled");
        }
    })
    .show();

Directory Picker with Multiple Selection

hs.ui.filePicker()
    .message("Choose directories to backup")
    .canChooseFiles(false)
    .canChooseDirectories(true)
    .allowsMultipleSelection(true)
    .onSelection((paths) => {
        if (paths) {
            paths.forEach(p => print("Dir: " + p));
        }
    })
    .show();

Properties

This type has no properties.

Methods

message(text)

Set the message displayed in the picker

Parameters

  • text string

    The message text

Returns

HSUIFilePicker - Self for chaining

defaultPath(path)

Set the starting directory

Parameters

  • path string

    Path to directory (supports `~` for home)

Returns

HSUIFilePicker - Self for chaining

canChooseFiles(value)

Set whether files can be selected

Parameters

  • value boolean

    true to allow file selection (default: true)

Returns

HSUIFilePicker - Self for chaining

canChooseDirectories(value)

Set whether directories can be selected

Parameters

  • value boolean

    true to allow directory selection (default: false)

Returns

HSUIFilePicker - Self for chaining

allowsMultipleSelection(value)

Set whether multiple items can be selected

Parameters

  • value boolean

    true to allow multiple selection (default: false)

Returns

HSUIFilePicker - Self for chaining

allowedFileTypes(types)

Restrict to specific file types

Parameters

  • types string[]

    Array of file extensions (e.g., ["txt", "md"])

Returns

HSUIFilePicker - Self for chaining

resolvesAliases(value)

Set whether to resolve symbolic links

Parameters

  • value boolean

    true to resolve aliases (default: true)

Returns

HSUIFilePicker - Self for chaining

onSelection(callback)

Set the callback for file selection

Parameters

  • callback JSValue

    Function receiving selected path(s) or null if cancelled

Returns

HSUIFilePicker - Self for chaining

show()

Show the file picker dialog

Parameters

None

Returns

Nothing