hammerspoon2-docs
    Preparing search index...

    Class HSUIFilePicker

    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.

    hs.ui.filePicker()
    .message("Choose a file to open")
    .allowedFileTypes(["txt", "md", "js"])
    .onSelection((path) => {
    if (path) {
    console.log("Selected: " + path);
    } else {
    console.log("User cancelled");
    }
    })
    .show();
    hs.ui.filePicker()
    .message("Choose directories to backup")
    .canChooseFiles(false)
    .canChooseDirectories(true)
    .allowsMultipleSelection(true)
    .onSelection((paths) => {
    if (paths) {
    paths.forEach(p => console.log("Dir: " + p));
    }
    })
    .show();
    Index

    Constructors

    Methods

    • Restrict to specific file types

      Parameters

      • types: string[]

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

      Returns HSUIFilePicker

      Self for chaining

    • Set whether multiple items can be selected

      Parameters

      • value: boolean

        true to allow multiple selection (default: false)

      Returns HSUIFilePicker

      Self for chaining

    • Set whether directories can be selected

      Parameters

      • value: boolean

        true to allow directory selection (default: false)

      Returns HSUIFilePicker

      Self for chaining

    • Set whether files can be selected

      Parameters

      • value: boolean

        true to allow file selection (default: true)

      Returns HSUIFilePicker

      Self for chaining

    • Set the starting directory

      Parameters

      • path: string

        Path to directory (supports ~ for home)

      Returns HSUIFilePicker

      Self for chaining

    • Set the message displayed in the picker

      Parameters

      • text: string

        The message text

      Returns HSUIFilePicker

      Self for chaining

    • Set the callback for file selection

      Parameters

      • callback: (paths: string | string[] | null) => void

        Function receiving the selected path(s) or null if cancelled. Single selection receives a string; multiple selection receives an array of strings.

      Returns HSUIFilePicker

      Self for chaining

    • Set whether to resolve symbolic links

      Parameters

      • value: boolean

        true to resolve aliases (default: true)

      Returns HSUIFilePicker

      Self for chaining

    • Show the file picker dialog

      Returns void