HSUIFilePicker
Type
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
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:55
Parameters
-
textstringThe message text
Returns
HSUIFilePicker - Self for chaining
defaultPath(path)
Set the starting directory
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:60
Parameters
-
pathstringPath to directory (supports `~` for home)
Returns
HSUIFilePicker - Self for chaining
canChooseFiles(value)
Set whether files can be selected
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:65
Parameters
-
valuebooleantrue to allow file selection (default: true)
Returns
HSUIFilePicker - Self for chaining
canChooseDirectories(value)
Set whether directories can be selected
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:70
Parameters
-
valuebooleantrue to allow directory selection (default: false)
Returns
HSUIFilePicker - Self for chaining
allowsMultipleSelection(value)
Set whether multiple items can be selected
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:75
Parameters
-
valuebooleantrue to allow multiple selection (default: false)
Returns
HSUIFilePicker - Self for chaining
allowedFileTypes(types)
Restrict to specific file types
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:80
Parameters
-
typesstring[]Array of file extensions (e.g., ["txt", "md"])
Returns
HSUIFilePicker - Self for chaining
resolvesAliases(value)
Set whether to resolve symbolic links
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:85
Parameters
-
valuebooleantrue to resolve aliases (default: true)
Returns
HSUIFilePicker - Self for chaining
onSelection(callback)
Set the callback for file selection
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:92
Parameters
-
callbackJSValueFunction receiving selected path(s) or null if cancelled
Returns
HSUIFilePicker - Self for chaining
show()
Show the file picker dialog
Hammerspoon 2/Modules/hs.ui/Dialogs/HSUIFilePicker.swift:95
Parameters
None
Returns
Nothing