API Docs

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) -> HSUIFilePicker

Set the message displayed in the picker
message(text) -> HSUIFilePicker
Name Type Description
text string The message text
HSUIFilePicker
Self for chaining
hs.ui.filePicker().message("Pick a file").show()

defaultPath(path) -> HSUIFilePicker

Set the starting directory
defaultPath(path) -> HSUIFilePicker
Name Type Description
path string Path to directory (supports `~` for home)
HSUIFilePicker
Self for chaining
hs.ui.filePicker().defaultPath("~/Documents").show()

canChooseFiles(value) -> HSUIFilePicker

Set whether files can be selected
canChooseFiles(value) -> HSUIFilePicker
Name Type Description
value boolean true to allow file selection (default: true)
HSUIFilePicker
Self for chaining
hs.ui.filePicker().canChooseFiles(true).show()

canChooseDirectories(value) -> HSUIFilePicker

Set whether directories can be selected
canChooseDirectories(value) -> HSUIFilePicker
Name Type Description
value boolean true to allow directory selection (default: false)
HSUIFilePicker
Self for chaining
hs.ui.filePicker().canChooseDirectories(true).show()

allowsMultipleSelection(value) -> HSUIFilePicker

Set whether multiple items can be selected
allowsMultipleSelection(value) -> HSUIFilePicker
Name Type Description
value boolean true to allow multiple selection (default: false)
HSUIFilePicker
Self for chaining
hs.ui.filePicker().allowsMultipleSelection(true).show()

allowedFileTypes(types) -> HSUIFilePicker

Restrict to specific file types
allowedFileTypes(types) -> HSUIFilePicker
Name Type Description
types string[] Array of file extensions (e.g., ["txt", "md"])
HSUIFilePicker
Self for chaining
hs.ui.filePicker().allowedFileTypes(["txt", "md"]).show()

resolvesAliases(value) -> HSUIFilePicker

Set whether to resolve symbolic links
resolvesAliases(value) -> HSUIFilePicker
Name Type Description
value boolean true to resolve aliases (default: true)
HSUIFilePicker
Self for chaining
hs.ui.filePicker().resolvesAliases(false).show()

onSelection(callback) -> HSUIFilePicker

Set the callback for file selection
onSelection(callback) -> HSUIFilePicker
Name Type Description
callback JSValue Function receiving selected path(s) or null if cancelled
HSUIFilePicker
Self for chaining
hs.ui.filePicker()
    .onSelection((path) => console.log("picked:", path))
    .show()

show() -> None

Show the file picker dialog
show() -> None
None
hs.ui.filePicker().show()