HSUIFilePicker
TypeHSUIFilePicker
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
Declaration
message(text) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The message text |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker().message("Pick a file").show()
defaultPath(path) -> HSUIFilePicker
Set the starting directory
Declaration
defaultPath(path) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | Path to directory (supports `~` for home) |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker().defaultPath("~/Documents").show()
canChooseFiles(value) -> HSUIFilePicker
Set whether files can be selected
Declaration
canChooseFiles(value) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean | true to allow file selection (default: true) |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker().canChooseFiles(true).show()
canChooseDirectories(value) -> HSUIFilePicker
Set whether directories can be selected
Declaration
canChooseDirectories(value) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean | true to allow directory selection (default: false) |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker().canChooseDirectories(true).show()
allowsMultipleSelection(value) -> HSUIFilePicker
Set whether multiple items can be selected
Declaration
allowsMultipleSelection(value) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean | true to allow multiple selection (default: false) |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker().allowsMultipleSelection(true).show()
allowedFileTypes(types) -> HSUIFilePicker
Restrict to specific file types
Declaration
allowedFileTypes(types) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| types | string[] | Array of file extensions (e.g., ["txt", "md"]) |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker().allowedFileTypes(["txt", "md"]).show()
resolvesAliases(value) -> HSUIFilePicker
Set whether to resolve symbolic links
Declaration
resolvesAliases(value) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean | true to resolve aliases (default: true) |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker().resolvesAliases(false).show()
onSelection(callback) -> HSUIFilePicker
Set the callback for file selection
Declaration
onSelection(callback) -> HSUIFilePicker
Parameters
| Name | Type | Description |
|---|---|---|
| callback | JSValue | Function receiving selected path(s) or null if cancelled |
Returns
HSUIFilePicker
Self for chaining
Example
hs.ui.filePicker()
.onSelection((path) => console.log("picked:", path))
.show()
show() -> None
Show the file picker dialog
Declaration
show() -> None
Returns
None
Example
hs.ui.filePicker().show()